public static bool LinkStorageToSource(Assignment prof) { bool returnStatus = false; try { string sourceDir = prof.Source.FullName; string targetDir = prof.Target.FullName;// + @"\" + prof.Source.Name; if (!AnalyzeFolders.ExistsAsDirectory(targetDir)) { JunctionPoint.Create(@targetDir, @sourceDir, false); returnStatus = true; } else { returnStatus = false; } } catch (Exception exp) { MessageBox.Show(exp.Message); returnStatus = false; } return(returnStatus); }
public async Task CreateJunctionPointWithJunctionFsForDeepPath() { IFileSystem fs = new JunctionFs(new MemoryFileSystem()); UPath target = "/test1/sub1/sub2"; UPath junctionPointVirtualPath = "/virtual"; var junctionPoint = new JunctionPoint(junctionPointVirtualPath, target); fs.CreateDirectory(target); var entry = new DirectoryEntry(fs, target); var filePath = UPath.Combine(entry.Path, "test.txt"); await using var testFile = fs.CreateFile(filePath); await testFile.WriteAsync(Encoding.UTF8.GetBytes("123")); fs.CreateJunctionPoint(junctionPoint, overwrite: true); var virtualFilePath = UPath.Combine(junctionPointVirtualPath, "test.txt"); var virtualFile = fs.GetFileEntry(virtualFilePath); var physicalFile = fs.GetFileEntry(filePath); Assert.True(virtualFile.Exists); Assert.True(physicalFile.Exists); bool junctionPointExists = fs.JunctionPointExists(virtualFilePath); Assert.True(junctionPointExists); }
public void Create_ThrowsIfTargetDirectoryDoesNotExist() { string targetFolder = Path.Combine(tempFolder, "ADirectory"); string junctionPoint = Path.Combine(tempFolder, "SymLink"); JunctionPoint.Create(junctionPoint, targetFolder, false); }
public static bool MoveSourceToStorage(Assignment prof, IProgress <long> sizeFromHell, object _lock, CancellationToken ct) { string sourceDir = prof.Source.FullName; string targetDir = prof.Target.FullName;// + @"\" + prof.Source.Name; Console.WriteLine("Moving " + sourceDir + " to " + targetDir + " started"); bool returnStatus = false; try { returnStatus = CopyFolders(prof, sizeFromHell, _lock, ct); if (returnStatus == false) { return(returnStatus); } else { DirectoryInfo deletableDirInfo = prof.Source; deletableDirInfo.Delete(true); Console.WriteLine("Deleted " + sourceDir); if (!AnalyzeFolders.ExistsAsDirectory(sourceDir)) { JunctionPoint.Create(@sourceDir, @targetDir, false); Console.WriteLine("Created Link"); } } } catch (Exception exp) { MessageBox.Show(exp.Message); } Console.WriteLine("Moving " + sourceDir + " to " + targetDir + " finished with " + returnStatus); return(returnStatus); }
protected override void ProcessRecord() { if (ShouldProcess("Creating link from {0} to {1}")) { JunctionPoint.Create(sourcePath, destinationPath, overwrite); } }
public Item(FileSystemInfo info) { Info = info; if (info.IsReparsePoint()) { if (JunctionPoint.Exists(info.FullName)) { Type = ItemType.Junction; var reparse = JunctionPoint.GetTarget(info.FullName); LinkTarget = reparse.SubstituteName; PrintName = reparse.PrintName; } else { Type = info is FileInfo ? ItemType.FileSymlink : info is DirectoryInfo ? ItemType.DirSymlink : throw new Exception("unreachable 27117"); LinkTarget = File.GetLinkTargetInfo(info.FullName).PrintName; // this should throw for reparse points of unknown types (ie neither junction nor symlink) } } else if (info is FileInfo) { Type = ItemType.File; } else if (info is DirectoryInfo) { Type = ItemType.Dir; } else { throw new Exception("unreachable 61374"); } }
protected override void ProcessRecord() { if (ShouldProcess("Deleting link from {0}")) { JunctionPoint.Delete(path); } }
public void Create_ThrowsIfTargetDirectoryDoesNotExist() { var targetFolder = this.tempFolder.Combine("ADirectory"); var junctionPoint = this.tempFolder.Combine("SymLink"); Assert.Throws <IOException>(() => JunctionPoint.Create(junctionPoint, targetFolder, false), "Target path does not exist or is not a directory."); }
public void TestDeleteDirectory_JunctionPoint() { var targetFolder = rootTestDir.Combine("ADirectory"); var junctionPoint = rootTestDir.Combine("SymLink"); targetFolder.CreateDirectory(); try { var targetFile = targetFolder.Combine("AFile"); File.Create(targetFile).Close(); try { JunctionPoint.Create(junctionPoint, targetFolder, overwrite: false); Assert.IsTrue(File.Exists(targetFolder.Combine("AFile")), "File should be accessible."); Assert.IsTrue(File.Exists(junctionPoint.Combine("AFile")), "File should be accessible via the junction point."); Directory.Delete(junctionPoint, false); Assert.IsTrue(File.Exists(targetFolder.Combine("AFile")), "File should be accessible."); Assert.IsFalse(JunctionPoint.Exists(junctionPoint), "Junction point should not exist now."); Assert.IsTrue(!File.Exists(junctionPoint.Combine("AFile")), "File should not be accessible via the junction point."); } finally { File.Delete(targetFile); } } finally { Directory.Delete(targetFolder); } }
public void MklinkH() { var txt = AllExtensions.txt; SetFor(LinkType.H); JunctionPoint.MklinkH(H() + txt, target + txt); }
public void Delete_CalledOnAFile() { File.Create(Path.Combine(tempFolder, "AFile")).Close(); Assert.Throws <IOException>(() => JunctionPoint.Delete(Path.Combine(tempFolder, "AFile")), "Path is not a junction point."); }
static void Delete(DirectoryInfo directory, int depth, IOResult logger) { if (JunctionPoint.Exists(directory.FullName)) { JunctionPoint.Delete(directory.FullName); } else if (!Directory.Exists(directory.FullName)) { return; } try { foreach (var fileInfo in directory.EnumerateFiles("*", SearchOption.TopDirectoryOnly)) { File.Delete(fileInfo.FullName); } foreach (var directoryInfo in directory.EnumerateDirectories("*", SearchOption.TopDirectoryOnly)) { var back = string.Join("\\", Enumerable.Repeat("..", depth)); Delete(directoryInfo, depth + 1, logger); } Directory.Delete(directory.FullName); } catch (Exception ex) { logger.Fail(ex); } }
private void createButton_Click(object sender, EventArgs e) { string origin = junctionTextBox.Text; string target = targetTextBox.Text; if (origin.Length == 0) { ActiveControl = junctionTextBox; System.Media.SystemSounds.Exclamation.Play(); return; } else if (target.Length == 0) { ActiveControl = targetTextBox; System.Media.SystemSounds.Exclamation.Play(); return; } if (!Directory.Exists(target)) { DialogResult recursionCaution = MessageBox.Show("There is no folder at " + target + ", please select a folder that the junction can target", "Folder doesn't exist", MessageBoxButtons.OK); } DialogResult confirmDialog = MessageBox.Show("Are you sure you want to create a junction at " + origin + " that links to " + target + "?", "Confirmation", MessageBoxButtons.YesNo); if (confirmDialog == DialogResult.No) { return; } JunctionPoint.Create(origin, target, true); SQLiteManager.AddJunction(origin, target); }
public void ShouldCreateJunctionPoint() { var path = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), Path.GetRandomFileName()); Directory.CreateDirectory(path); var file = Path.Combine(path, "file.txt"); using (File.Create(file)) { } var junctionPath = string.Format("{0}+junction", path); JunctionPoint.Create(junctionPath, path, true); var junctionFiles = Directory.GetFiles(junctionPath); Assert.That(junctionFiles.Length, Is.EqualTo(1)); Assert.That(junctionFiles[0], Is.EqualTo(Path.Combine(junctionPath, "file.txt"))); JunctionPoint.Delete(junctionPath); Assert.That(Directory.Exists(junctionPath), Is.False); Assert.That(File.Exists(file), Is.True); }
private static void Link(string link, string target) { var linkDirectory = new DirectoryInfo(link); var targetDirectory = new DirectoryInfo(target); if (linkDirectory.Exists) { // 如果目标目录存在,则检查一下这是否是一个目录联接。 if (JunctionPoint.Exists(linkDirectory.FullName)) { // 如果是目录联接,则可以删除重建。 LinkCore(linkDirectory, targetDirectory); } else { // 如果是文件夹,则检查里面是否存在文件,是否需要备份。 var hasContent = linkDirectory.EnumerateFileSystemInfos().Any(); if (hasContent) { linkDirectory.MoveTo($"{linkDirectory.FullName}.bak"); } else { linkDirectory.Delete(); LinkCore(linkDirectory, targetDirectory); } } } else { LinkCore(linkDirectory, targetDirectory); } }
static void ConvertJunction(string dir) { string from = JunctionPoint.GetTarget(dir); if (from != "") { string target = from.TrimEnd('\\'); try { File.Copy(target, dir + "-junction", true); Directory.Delete(dir); File.Move(dir + "-junction", dir); Console.WriteLine("Created " + dir); } catch (ArgumentException ex) { Console.WriteLine(""); Console.WriteLine("Conversion of " + target + " -> " + dir + " failed: " + ex.ToString()); Console.WriteLine(""); } catch (IOException ioex) { Console.WriteLine(""); Console.WriteLine("Conversion of " + target + " -> " + dir + " failed (IO): " + ioex.ToString()); Console.WriteLine(""); } } else { Console.WriteLine("No target for " + dir); } }
public void Create_ThrowsIfTargetDirectoryDoesNotExist() { string targetFolder = Path.Combine(tempFolder, "ADirectory"); string junctionPoint = Path.Combine(tempFolder, "SymLink"); Assert.Throws <IOException>(() => JunctionPoint.Create(junctionPoint, targetFolder, false), "Target path does not exist or is not a directory."); }
public void MklinkJ() { SetFor(LinkType.J); var j = J(); JunctionPoint.Delete(j); JunctionPoint.MklinkJ(j, target); }
public void Create_ThrowsIfOverwriteNotSpecifiedAndDirectoryExists() { string targetFolder = Path.Combine(tempFolder, "ADirectory"); string junctionPoint = Path.Combine(tempFolder, "SymLink"); Directory.CreateDirectory(junctionPoint); JunctionPoint.Create(junctionPoint, targetFolder, false); }
public void Create_ThrowsIfOverwriteNotSpecifiedAndDirectoryExists() { var targetFolder = this.tempFolder.Combine("ADirectory"); var junctionPoint = this.tempFolder.Combine("SymLink"); junctionPoint.CreateDirectory(); Assert.Throws <IOException>(() => JunctionPoint.Create(junctionPoint, targetFolder, false), "Directory already exists and overwrite parameter is false."); }
public static bool MoveStorageToSource(Assignment prof, IProgress <long> sizeFromHell, object _lock, CancellationToken ct) { string sourceDir = prof.Source.FullName; string targetDir = prof.Target.FullName;// + @"\" + prof.Source.Name; Console.WriteLine("Moving " + sourceDir + " to " + targetDir + " started"); bool returnStatus = false; try { /// find a junction, which has a different name, than the folder to be moved List <string> ListOfJunctions = prof.Source.GetDirectories().Select(dir => dir.FullName).ToList().Where(str => JunctionPoint.Exists(@str)).ToList(); List <string> ListOfTargets = ListOfJunctions.Select(str => JunctionPoint.GetTarget(@str)).ToList(); List <Tuple <string, string> > pairsOfJaT = new List <Tuple <string, string> >(); for (int i = 0; i < ListOfJunctions.Count; i++) { string JunctionName = (new DirectoryInfo(ListOfJunctions[i])).Name; string TargetName = (new DirectoryInfo(ListOfTargets[i])).Name; if (JunctionName != TargetName) { pairsOfJaT.Add(new Tuple <string, string>(JunctionName, TargetName)); } } string renamedJunction = null; if (pairsOfJaT.Count > 0) { renamedJunction = pairsOfJaT.FirstOrDefault(str => str.Item2 == prof.Source.Name).Item1; } if (renamedJunction != null) { renamedJunction = prof.Target.Parent + @"\" + renamedJunction; } if (JunctionPoint.Exists(@targetDir)) { JunctionPoint.Delete(@targetDir); returnStatus = CopyFolders(prof, sizeFromHell, _lock, ct); } else if (JunctionPoint.Exists(@renamedJunction)) { JunctionPoint.Delete(@renamedJunction); returnStatus = CopyFolders(prof, sizeFromHell, _lock, ct); } if (returnStatus == true) { DirectoryInfo deletableDirInfo = prof.Source; deletableDirInfo.Delete(true); } } catch (Exception exp) { MessageBox.Show(exp.Message); } Console.WriteLine("Moving " + sourceDir + " to " + targetDir + " finished with " + returnStatus); return(returnStatus); }
public override Directory LinkTo(Path path) { if (!Exists()) { throw new System.IO.IOException("Source path does not exist or is not a directory."); } JunctionPoint.Create(GetDirectory(path.FullPath), Path.FullPath, true); return(new Win32Directory(path)); }
public void Create_ThrowsIfOverwriteNotSpecifiedAndDirectoryExists() { string targetFolder = Path.Combine(tempFolder, "ADirectory"); string junctionPoint = Path.Combine(tempFolder, "SymLink"); Directory.CreateDirectory(junctionPoint); Assert.Throws <IOException>(() => JunctionPoint.Create(junctionPoint, targetFolder, false), "Directory already exists and overwrite parameter is false."); }
public void ShouldGetTargetPathForJunction() { var path = IOPath.Combine(Environment.GetEnvironmentVariable("TEMP"), IOPath.GetRandomFileName()); Directory.CreateDirectory(path); var junctionPath = string.Format("{0}+junction", path); JunctionPoint.Create(junctionPath, path, true); Assert.That(ReparsePoint.GetTarget(junctionPath), Is.EqualTo(path)); }
public override void Delete() { if (IsHardLink) { JunctionPoint.Delete(Path.FullPath); } else { base.Delete(); } }
private void removeAllLinksToolStripMenuItem_Click(object sender, EventArgs e) { foreach (var v in model.Settings.InstalledVersions.OrderByDescending(version => version.VersionNumber)) { if (JunctionPoint.Exists(Path.Combine(v.Folder, "mlc01", "usr", "title"))) { JunctionPoint.Delete(Path.Combine(v.Folder, "mlc01", "usr", "title")); } } button3_Click(null, null); }
public static void MoveReplaceJunction(string origin, string target) { //Delete the junction JunctionPoint.Delete(origin); //Copy the folder back and delete the original folder (essentially moving the function) Program.CopyFolder(target, origin); Directory.Delete(target, true); //Update the SQLite database with the removal of the junction SQLiteManager.RemoveJunction(origin); Program.Log("INFO: Moved " + target + " to " + origin); }
public override void Delete() { if (IsHardLink) { JunctionPoint.Delete(Path); } else { LongPathDirectory.Delete(Path, true); } }
public static void MoveWithJunction(string origin, string target) { //Copy folder and delete the original folder (essentially a move" Program.CopyFolder(origin, target); Directory.Delete(origin, true); Program.Log("INFO: Moved " + origin + " to " + target); //Create a junction at the original location pointing to the new location JunctionPoint.Create(origin, target, true); //Update the SQLite database with the new junction created SQLiteManager.AddJunction(origin, target); }
public static bool CreateDirectory(string target, string source) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { JunctionPoint.Create(target, source, true); } else { LostTech.IO.Links.Symlink.CreateForDirectory(source, target); } return(Directory.Exists(target)); }