diff --git a/src/NzbDrone.Common.Test/DiskTests/DiskTransferServiceFixture.cs b/src/NzbDrone.Common.Test/DiskTests/DiskTransferServiceFixture.cs index 04c5cb40a0..c930f65332 100644 --- a/src/NzbDrone.Common.Test/DiskTests/DiskTransferServiceFixture.cs +++ b/src/NzbDrone.Common.Test/DiskTests/DiskTransferServiceFixture.cs @@ -540,6 +540,27 @@ public void MoveFolder_should_rename_caseinsensitive_folder() source.FullName.GetActualCasing().Should().Be(destination.FullName); } + [Test] + public void TransferFile_should_find_files_with_multiple_slashes_within_their_path() + { + WithRealDiskProvider(); + + var root = GetFilledTempFolder(); + var rootDir = root.FullName; + var fromFileName = "source-file"; + var from = Path.Combine(rootDir, fromFileName); + var to = Path.Combine(rootDir, "destination-file"); + + var oneSlash = new string(Path.DirectorySeparatorChar, 1); + var threeSlashes = new string(Path.DirectorySeparatorChar, 3); + var overSlashed = Path.Combine(rootDir.Replace(oneSlash, threeSlashes), fromFileName); + + File.WriteAllText(from, "Source file"); + + var mode = Subject.TransferFile(overSlashed, to, TransferMode.Copy); + mode.Should().Be(TransferMode.Copy); + } + [Test] public void should_throw_if_destination_is_readonly() { diff --git a/src/NzbDrone.Common/Disk/DiskTransferService.cs b/src/NzbDrone.Common/Disk/DiskTransferService.cs index f89c31b212..2bcf3474b8 100644 --- a/src/NzbDrone.Common/Disk/DiskTransferService.cs +++ b/src/NzbDrone.Common/Disk/DiskTransferService.cs @@ -28,15 +28,21 @@ public DiskTransferService(IDiskProvider diskProvider, Logger logger) private string ResolveRealParentPath(string path) { - var parentPath = path.GetParentPath(); - if (!_diskProvider.FolderExists(parentPath)) + var testExists = path.GetParentPath(); + if (!_diskProvider.FolderExists(testExists)) { return path; } - var realParentPath = parentPath.GetActualCasing(); + var cleanPath = path.GetCleanPath(); + if (cleanPath != path) + { + _logger.Warn($"Path '{path}' is not clean, using '{cleanPath}' to resolve the parent path instead"); + } - var partialChildPath = path.Substring(parentPath.Length); + var parentPath = cleanPath.GetParentPath(); + var realParentPath = parentPath.GetActualCasing(); + var partialChildPath = cleanPath.Substring(parentPath.Length); return realParentPath + partialChildPath; }