1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-09-11 03:52:33 +02:00

case insensitive match for unmapped folders.

This commit is contained in:
Keivan Beigi 2013-08-20 12:28:46 -07:00
parent 1c62782fcd
commit c13195046d
6 changed files with 44 additions and 40 deletions

View File

@ -127,29 +127,7 @@ public void MoveFolder_should_overwrite_existing_folder()
}
[TestCase(@"C:\", @"C:\")]
[TestCase(@"C:\\", @"C:\")]
[TestCase(@"c:\", @"C:\")]
[TestCase(@"c:\Test", @"C:\Test\\")]
[TestCase(@"c:\\\\\Test", @"C:\Test\\")]
[TestCase(@"c:\Test\\\\", @"C:\Test\\")]
[TestCase(@"c:\Test", @"C:\Test\\")]
[TestCase(@"\\Server\pool", @"\\Server\pool")]
[TestCase(@"\\Server\pool\", @"\\Server\pool")]
[TestCase(@"\\Server\pool", @"\\Server\pool\")]
[TestCase(@"\\Server\pool\", @"\\Server\pool\")]
[TestCase(@"\\smallcheese\DRIVE_G\TV-C\Simspsons", @"\\smallcheese\DRIVE_G\TV-C\Simspsons")]
public void paths_should_be_equal(string first, string second)
{
DiskProvider.PathEquals(first.AsOsAgnostic(), second.AsOsAgnostic()).Should().BeTrue();
}
[TestCase(@"C:\Test", @"C:\Test2\")]
[TestCase(@"C:\Test\Test", @"C:\TestTest\")]
public void paths_should_not_be_equal(string first, string second)
{
DiskProvider.PathEquals(first.AsOsAgnostic(), second.AsOsAgnostic()).Should().BeFalse();
}
[Test]
public void empty_folder_should_return_folder_modified_date()

View File

@ -56,6 +56,30 @@ public void Clean_Path_Linux(string dirty, string clean)
result.Should().Be(clean);
}
[TestCase(@"C:\", @"C:\")]
[TestCase(@"C:\\", @"C:\")]
[TestCase(@"c:\", @"C:\")]
[TestCase(@"c:\Test", @"C:\Test\\")]
[TestCase(@"c:\\\\\Test", @"C:\Test\\")]
[TestCase(@"c:\Test\\\\", @"C:\Test\\")]
[TestCase(@"c:\Test", @"C:\Test\\")]
[TestCase(@"\\Server\pool", @"\\Server\pool")]
[TestCase(@"\\Server\pool\", @"\\Server\pool")]
[TestCase(@"\\Server\pool", @"\\Server\pool\")]
[TestCase(@"\\Server\pool\", @"\\Server\pool\")]
[TestCase(@"\\smallcheese\DRIVE_G\TV-C\Simspsons", @"\\smallcheese\DRIVE_G\TV-C\Simspsons")]
public void paths_should_be_equal(string first, string second)
{
first.AsOsAgnostic().PathEquals(second.AsOsAgnostic()).Should().BeTrue();
}
[TestCase(@"C:\Test", @"C:\Test2\")]
[TestCase(@"C:\Test\Test", @"C:\TestTest\")]
public void paths_should_not_be_equal(string first, string second)
{
first.AsOsAgnostic().PathEquals(second.AsOsAgnostic()).Should().BeFalse();
}
[Test]
public void normalize_path_exception_empty()
{

View File

@ -41,12 +41,12 @@ public interface IDiskProvider
string GetPathRoot(string path);
void SetPermissions(string filename, WellKnownSidType accountSid, FileSystemRights rights, AccessControlType controlType);
bool IsParent(string parentPath, string childPath);
FileAttributes GetFileAttributes(string path);
FileAttributes GetFileAttributes(string path);
}
public class DiskProvider : IDiskProvider
{
enum TransferAction
enum TransferAction
{
Copy,
Move
@ -260,7 +260,7 @@ public void MoveFile(string source, string destination)
Ensure.That(() => source).IsValidPath();
Ensure.That(() => destination).IsValidPath();
if (PathEquals(source, destination))
if (source.PathEquals(destination))
{
Logger.Warn("Source and destination can't be the same {0}", source);
return;
@ -303,7 +303,7 @@ public long GetAvilableSpace(string path)
throw new DirectoryNotFoundException(path);
}
return driveInfo.AvailableFreeSpace;
return driveInfo.AvailableFreeSpace;
}
var root = GetPathRoot(path);
@ -312,7 +312,7 @@ public long GetAvilableSpace(string path)
throw new DirectoryNotFoundException(root);
return DriveFreeSpaceEx(root);
}
}
private static long DriveFreeSpaceEx(string folderName)
{
@ -352,13 +352,6 @@ public void WriteAllText(string filename, string contents)
File.WriteAllText(filename, contents);
}
public static bool PathEquals(string firstPath, string secondPath)
{
Ensure.That(() => firstPath).IsValidPath();
Ensure.That(() => secondPath).IsValidPath();
return String.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath(), StringComparison.InvariantCultureIgnoreCase);
}
public void FileSetLastWriteTimeUtc(string path, DateTime dateTime)
{

View File

@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using NzbDrone.Common.EnsureThat;
using NzbDrone.Common.EnvironmentInfo;
@ -35,6 +36,14 @@ public static string CleanFilePath(this string path)
}
public static bool PathEquals(this string firstPath, string secondPath)
{
Ensure.That(() => firstPath).IsValidPath();
Ensure.That(() => secondPath).IsValidPath();
return String.Equals(firstPath.CleanFilePath(), secondPath.CleanFilePath(), StringComparison.InvariantCultureIgnoreCase);
}
public static bool ContainsInvalidPathChars(this string text)
{
return text.IndexOfAny(Path.GetInvalidPathChars()) >= 0;

View File

@ -65,7 +65,7 @@ private EpisodeFile MoveFile(EpisodeFile episodeFile, string destinationFilename
throw new FileNotFoundException("Episode file path does not exist", episodeFile.Path);
}
if (DiskProvider.PathEquals(episodeFile.Path, destinationFilename))
if (episodeFile.Path.PathEquals(destinationFilename))
{
throw new SameFilenameException("File not moved, source and destination are the same", episodeFile.Path);
}

View File

@ -73,11 +73,11 @@ public virtual RootFolder Add(RootFolder rootFolder)
if (!_diskProvider.FolderExists(rootFolder.Path))
throw new DirectoryNotFoundException("Can't add root directory that doesn't exist.");
if (all.Exists(r => DiskProvider.PathEquals(r.Path, rootFolder.Path)))
if (all.Exists(r => r.Path.PathEquals(rootFolder.Path)))
throw new InvalidOperationException("Recent directory already exists.");
if (!String.IsNullOrWhiteSpace(_configService.DownloadedEpisodesFolder) &&
DiskProvider.PathEquals(_configService.DownloadedEpisodesFolder, rootFolder.Path))
_configService.DownloadedEpisodesFolder.PathEquals(rootFolder.Path))
throw new InvalidOperationException("Drone Factory folder cannot be used.");
_rootFolderRepository.Insert(rootFolder);
@ -109,10 +109,10 @@ public virtual List<UnmappedFolder> GetUnmappedFolders(string path)
foreach (string seriesFolder in _diskProvider.GetDirectories(path))
{
if (!series.Any(s => s.Path == seriesFolder))
if (!series.Any(s => s.Path.PathEquals(seriesFolder)))
{
var di = new DirectoryInfo(seriesFolder.Normalize());
results.Add(new UnmappedFolder{ Name = di.Name, Path = di.FullName });
results.Add(new UnmappedFolder { Name = di.Name, Path = di.FullName });
}
}