mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2026-04-23 22:45:06 -04:00
Added: Dynamic paths cleanup old folders now!
Old folder is now only left behind if extra files are also present in new dir and cannot be overwritten. Generally Dynamic Paths should be more stable now. Fixes #2048
This commit is contained in:
@@ -245,6 +245,25 @@ namespace NzbDrone.Common.Disk
|
||||
File.Move(source, destination);
|
||||
}
|
||||
|
||||
public void MoveFolder(string source, string destination, bool overwrite = false)
|
||||
{
|
||||
Ensure.That(source, () => source).IsValidPath();
|
||||
Ensure.That(destination, () => destination).IsValidPath();
|
||||
|
||||
if (source.PathEquals(destination))
|
||||
{
|
||||
throw new IOException(string.Format("Source and destination can't be the same {0}", source));
|
||||
}
|
||||
|
||||
if (FolderExists(destination) && overwrite)
|
||||
{
|
||||
DeleteFolder(destination, true);
|
||||
}
|
||||
|
||||
RemoveReadOnlyFolder(source);
|
||||
Directory.Move(source, destination);
|
||||
}
|
||||
|
||||
public abstract bool TryCreateHardLink(string source, string destination);
|
||||
|
||||
public void DeleteFolder(string path, bool recursive)
|
||||
@@ -371,6 +390,20 @@ namespace NzbDrone.Common.Disk
|
||||
}
|
||||
}
|
||||
|
||||
private static void RemoveReadOnlyFolder(string path)
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
var dirInfo = new DirectoryInfo(path);
|
||||
|
||||
if (dirInfo.Attributes.HasFlag(FileAttributes.ReadOnly))
|
||||
{
|
||||
var newAttributes = dirInfo.Attributes & ~(FileAttributes.ReadOnly);
|
||||
dirInfo.Attributes = newAttributes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FileAttributes GetFileAttributes(string path)
|
||||
{
|
||||
return File.GetAttributes(path);
|
||||
|
||||
Reference in New Issue
Block a user