fix: Migration logic now handles symlinks (sort of)

Symlinks are difficult to deal with. At this point, it was still failing
to migrate the `.config/recyclarr/repo` directory. Even though it still
doesn't work 100%, I'm going to leave it as it is and instead simplify
what gets migrated later.
pull/76/head
Robert Dailey 2 years ago
parent f5ce60589d
commit bf7d884183

@ -18,16 +18,35 @@ public static class FileSystemExtensions
foreach (var dir in directories)
{
console?.Output.WriteLine($" - Attributes: {dir.Attributes}");
// Is it a symbolic link?
if ((dir.Attributes & FileAttributes.ReparsePoint) != 0)
{
var newPath = RelocatePath(dir.FullName, targetDir, destDir);
fs.Directory.CreateDirectory(fs.Path.GetDirectoryName(newPath));
console?.Output.WriteLine($" - Symlink: {dir.FullName} :: TO :: {newPath}");
dir.MoveTo(newPath);
continue;
}
// For real directories, move all the files inside
foreach (var file in dir.EnumerateFiles())
{
var newPath = Regex.Replace(file.FullName, $"^{Regex.Escape(targetDir)}", destDir);
var newPath = RelocatePath(file.FullName, targetDir, destDir);
fs.Directory.CreateDirectory(fs.Path.GetDirectoryName(newPath));
console?.Output.WriteLine($" - Moving: {file.FullName} :: TO :: {newPath}");
file.MoveTo(newPath);
}
// Delete the directory now that it is empty.
console?.Output.WriteLine($" - Deleting: {dir.FullName}");
dir.Delete();
}
}
private static string RelocatePath(string path, string oldDir, string newDir)
{
return Regex.Replace(path, $"^{Regex.Escape(oldDir)}", newDir);
}
}

Loading…
Cancel
Save