case insensitive match for unmapped folders.

pull/4/head
Keivan Beigi 11 years ago
parent 1c62782fcd
commit c13195046d

@ -127,29 +127,7 @@ namespace NzbDrone.Common.Test.DiskProviderTests
}
[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()

@ -56,6 +56,30 @@ namespace NzbDrone.Common.Test
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()
{

@ -41,12 +41,12 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Common
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 @@ namespace NzbDrone.Common
throw new DirectoryNotFoundException(path);
}
return driveInfo.AvailableFreeSpace;
return driveInfo.AvailableFreeSpace;
}
var root = GetPathRoot(path);
@ -312,7 +312,7 @@ namespace NzbDrone.Common
throw new DirectoryNotFoundException(root);
return DriveFreeSpaceEx(root);
}
}
private static long DriveFreeSpaceEx(string folderName)
{
@ -352,13 +352,6 @@ namespace NzbDrone.Common
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)
{

@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using NzbDrone.Common.EnsureThat;
using NzbDrone.Common.EnvironmentInfo;
@ -35,6 +36,14 @@ namespace NzbDrone.Common
}
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;

@ -65,7 +65,7 @@ namespace NzbDrone.Core.MediaFiles
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);
}

@ -73,11 +73,11 @@ namespace NzbDrone.Core.RootFolders
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 @@ namespace NzbDrone.Core.RootFolders
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 });
}
}

Loading…
Cancel
Save