aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2015-09-30 01:15:25 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2015-09-30 01:15:25 -0400
commit56371421006c72356fe4b04d50f5f57b05102b94 (patch)
treefb664c1b3a7fa562c1ff3d30815efb28678f46ab
parent1cf65f1a2ef6e8b7fcfe0b5ee75fc738c4af723e (diff)
#1189 - Auto-Organize: Fix PathTooLongException due to long EpisodeTitle
-rw-r--r--MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs23
1 files changed, 17 insertions, 6 deletions
diff --git a/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs b/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs
index aa5a52512..cdac598fd 100644
--- a/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs
+++ b/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs
@@ -182,7 +182,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
_logger.Info("Sorting file {0} to new path {1}", sourcePath, newPath);
result.TargetPath = newPath;
- var fileExists = _fileSystem.FileExists(result.TargetPath);
+ var fileExists = _fileSystem.FileExists(result.TargetPath);
var otherDuplicatePaths = GetOtherDuplicatePaths(result.TargetPath, series, seasonNumber, episodeNumber, endingEpiosdeNumber);
if (!overwriteExisting)
@@ -272,7 +272,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
var destination = Path.Combine(directory, filename);
- _fileSystem.MoveFile(file, destination);
+ _fileSystem.MoveFile(file, destination);
}
}
}
@@ -332,19 +332,19 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
{
_libraryMonitor.ReportFileSystemChangeBeginning(result.TargetPath);
- _fileSystem.CreateDirectory(Path.GetDirectoryName(result.TargetPath));
+ _fileSystem.CreateDirectory(Path.GetDirectoryName(result.TargetPath));
- var targetAlreadyExists = _fileSystem.FileExists(result.TargetPath);
+ var targetAlreadyExists = _fileSystem.FileExists(result.TargetPath);
try
{
if (targetAlreadyExists || options.CopyOriginalFile)
{
- _fileSystem.CopyFile(result.OriginalPath, result.TargetPath, true);
+ _fileSystem.CopyFile(result.OriginalPath, result.TargetPath, true);
}
else
{
- _fileSystem.MoveFile(result.OriginalPath, result.TargetPath);
+ _fileSystem.MoveFile(result.OriginalPath, result.TargetPath);
}
result.Status = FileSortingStatus.Success;
@@ -439,6 +439,17 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
newPath = Path.Combine(newPath, episodeFileName);
+ // Try to account for windows limitations by removing the episode title
+ if (newPath.Length > 255)
+ {
+ var extension = Path.GetExtension(episodeFileName);
+ var fileName = Path.GetFileNameWithoutExtension(episodeFileName);
+ fileName = fileName.Replace(episode.Name, string.Empty, StringComparison.OrdinalIgnoreCase);
+ episodeFileName = Path.ChangeExtension(fileName, extension);
+
+ newPath = Path.Combine(newPath, episodeFileName);
+ }
+
return newPath;
}