예제 #1
0
        public void TestGetSymbolicLinkTarget()
        {
            var symlink = new FileInfo("link_to_tmp_directory");

            SymbolicLinkHelper.CreateSymbolicLink(new DirectoryInfo("tmp"), symlink);
            var result = SymbolicLinkHelper.GetSymbolicLinkTarget(new FileInfo("link_to_tmp_directory"));

            symlink.Delete();
            Assert.AreEqual("tmp", result);
        }
예제 #2
0
        public static string GetSymbolicLinkTargetAbsolute(FileSystemInfo symlinkFileSystemInfo)
        {
            // Get the symlink's targetPath and
            // if it is relative make it absolute based on symlinkFileSystemInfo.
            var targetPath = SymbolicLinkHelper.GetSymbolicLinkTarget(symlinkFileSystemInfo);

            if (!Path.IsPathRooted(targetPath))
            {
                var parentDir = PathUtil.GetParent(symlinkFileSystemInfo);
                targetPath = Path.Combine(parentDir.FullName, targetPath);
                // Normalize path.
                targetPath = Path.GetFullPath(targetPath);
            }

            // Remove trailing directory separator char if any.
            var lastChar = targetPath[targetPath.Length - 1];

            if (targetPath.Length > 1 && (lastChar == Path.AltDirectorySeparatorChar || lastChar == Path.DirectorySeparatorChar))
            {
                targetPath = targetPath.Substring(0, targetPath.Length - 1);
            }

            return(targetPath);
        }