|
|
|
@ -72,7 +72,7 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
private void CheckFolderExists(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
if (!FolderExists(path))
|
|
|
|
|
{
|
|
|
|
@ -82,7 +82,7 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
private void CheckFileExists(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
if (!FileExists(path))
|
|
|
|
|
{
|
|
|
|
@ -100,19 +100,19 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public bool FolderExists(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
return _fileSystem.Directory.Exists(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool FileExists(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
return FileExists(path, PathStringComparison);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool FileExists(string path, StringComparison stringComparison)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
switch (stringComparison)
|
|
|
|
|
{
|
|
|
|
@ -132,7 +132,7 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public bool FolderWritable(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
@ -151,42 +151,42 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public bool FolderEmpty(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
return _fileSystem.Directory.EnumerateFileSystemEntries(path).Empty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string[] GetDirectories(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
return _fileSystem.Directory.GetDirectories(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string[] GetDirectories(string path, SearchOption searchOption)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
return _fileSystem.Directory.GetDirectories(path, "*", searchOption);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string[] GetFiles(string path, SearchOption searchOption)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
return _fileSystem.Directory.GetFiles(path, "*.*", searchOption);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long GetFolderSize(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
return GetFiles(path, SearchOption.AllDirectories).Sum(e => _fileSystem.FileInfo.FromFileName(e).Length);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long GetFileSize(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
if (!FileExists(path))
|
|
|
|
|
{
|
|
|
|
@ -199,13 +199,13 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public void CreateFolder(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
_fileSystem.Directory.CreateDirectory(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeleteFile(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
Logger.Trace("Deleting file: {0}", path);
|
|
|
|
|
|
|
|
|
|
RemoveReadOnly(path);
|
|
|
|
@ -215,8 +215,8 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public void CloneFile(string source, string destination, bool overwrite = false)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(source, () => source).IsValidPath();
|
|
|
|
|
Ensure.That(destination, () => destination).IsValidPath();
|
|
|
|
|
Ensure.That(source, () => source).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
Ensure.That(destination, () => destination).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
if (source.PathEquals(destination))
|
|
|
|
|
{
|
|
|
|
@ -233,8 +233,8 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public void CopyFile(string source, string destination, bool overwrite = false)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(source, () => source).IsValidPath();
|
|
|
|
|
Ensure.That(destination, () => destination).IsValidPath();
|
|
|
|
|
Ensure.That(source, () => source).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
Ensure.That(destination, () => destination).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
if (source.PathEquals(destination))
|
|
|
|
|
{
|
|
|
|
@ -251,8 +251,8 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public void MoveFile(string source, string destination, bool overwrite = false)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(source, () => source).IsValidPath();
|
|
|
|
|
Ensure.That(destination, () => destination).IsValidPath();
|
|
|
|
|
Ensure.That(source, () => source).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
Ensure.That(destination, () => destination).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
if (source.PathEquals(destination))
|
|
|
|
|
{
|
|
|
|
@ -270,8 +270,8 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public void MoveFolder(string source, string destination)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(source, () => source).IsValidPath();
|
|
|
|
|
Ensure.That(destination, () => destination).IsValidPath();
|
|
|
|
|
Ensure.That(source, () => source).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
Ensure.That(destination, () => destination).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
Directory.Move(source, destination);
|
|
|
|
|
}
|
|
|
|
@ -300,7 +300,7 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public void DeleteFolder(string path, bool recursive)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
var files = _fileSystem.Directory.GetFiles(path, "*.*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
|
|
|
|
|
Array.ForEach(files, RemoveReadOnly);
|
|
|
|
@ -310,14 +310,14 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public string ReadAllText(string filePath)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(filePath, () => filePath).IsValidPath();
|
|
|
|
|
Ensure.That(filePath, () => filePath).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
return _fileSystem.File.ReadAllText(filePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void WriteAllText(string filename, string contents)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(filename, () => filename).IsValidPath();
|
|
|
|
|
Ensure.That(filename, () => filename).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
RemoveReadOnly(filename);
|
|
|
|
|
|
|
|
|
|
// File.WriteAllText is broken on net core when writing to some CIFS mounts
|
|
|
|
@ -333,14 +333,14 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public void FolderSetLastWriteTime(string path, DateTime dateTime)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
_fileSystem.Directory.SetLastWriteTimeUtc(path, dateTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void FileSetLastWriteTime(string path, DateTime dateTime)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
_fileSystem.File.SetLastWriteTime(path, dateTime);
|
|
|
|
|
}
|
|
|
|
@ -362,14 +362,14 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public virtual string GetPathRoot(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
return Path.GetPathRoot(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetParentFolder(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
var parent = _fileSystem.Directory.GetParent(path.TrimEnd(Path.DirectorySeparatorChar));
|
|
|
|
|
|
|
|
|
@ -402,7 +402,7 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public void EmptyFolder(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
foreach (var file in GetFiles(path, SearchOption.TopDirectoryOnly))
|
|
|
|
|
{
|
|
|
|
@ -492,7 +492,7 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public List<IDirectoryInfo> GetDirectoryInfos(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
var di = _fileSystem.DirectoryInfo.FromDirectoryName(path);
|
|
|
|
|
|
|
|
|
@ -501,13 +501,13 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public IDirectoryInfo GetDirectoryInfo(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
return _fileSystem.DirectoryInfo.FromDirectoryName(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<IFileInfo> GetFileInfos(string path, SearchOption searchOption = SearchOption.TopDirectoryOnly)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
|
|
|
|
|
var di = _fileSystem.DirectoryInfo.FromDirectoryName(path);
|
|
|
|
|
|
|
|
|
@ -516,7 +516,7 @@ namespace NzbDrone.Common.Disk
|
|
|
|
|
|
|
|
|
|
public IFileInfo GetFileInfo(string path)
|
|
|
|
|
{
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath();
|
|
|
|
|
Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs);
|
|
|
|
|
return _fileSystem.FileInfo.FromFileName(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|