Skip to content

Commit

Permalink
improve smb support
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed May 4, 2017
1 parent fcfcb98 commit 7cc91bb
Show file tree
Hide file tree
Showing 82 changed files with 256 additions and 151 deletions.
4 changes: 2 additions & 2 deletions BDInfo/BDROM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public BDROM(
}

DirectoryRoot =
_fileSystem.GetDirectoryInfo(Path.GetDirectoryName(DirectoryBDMV.FullName));
_fileSystem.GetDirectoryInfo(_fileSystem.GetDirectoryName(DirectoryBDMV.FullName));
DirectoryBDJO =
GetDirectory("BDJO", DirectoryBDMV, 0);
DirectoryCLIPINF =
Expand Down Expand Up @@ -349,7 +349,7 @@ private FileSystemMetadata GetDirectoryBDMV(
{
return dir;
}
var parentFolder = Path.GetDirectoryName(dir.FullName);
var parentFolder = _fileSystem.GetDirectoryName(dir.FullName);
if (string.IsNullOrEmpty(parentFolder))
{
dir = null;
Expand Down
2 changes: 1 addition & 1 deletion Emby.Common.Implementations/Devices/DeviceId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void SaveId(string id)
{
var path = CachePath;

_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));

lock (_syncLock)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ private async Task<HttpResponseInfo> GetCachedResponse(string responseCachePath,

private async Task CacheResponse(HttpResponseInfo response, string responseCachePath)
{
_fileSystem.CreateDirectory(Path.GetDirectoryName(responseCachePath));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(responseCachePath));

using (var responseStream = response.Content)
{
Expand Down
56 changes: 37 additions & 19 deletions Emby.Common.Implementations/IO/ManagedFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -546,24 +546,6 @@ private char GetDirectorySeparatorChar(string path)
return Path.DirectorySeparatorChar;
}

public bool AreEqual(string path1, string path2)
{
if (path1 == null && path2 == null)
{
return true;
}

if (path1 == null || path2 == null)
{
return false;
}

path1 = path1.TrimEnd(GetDirectorySeparatorChar(path1));
path2 = path2.TrimEnd(GetDirectorySeparatorChar(path2));

return string.Equals(path1, path2, StringComparison.OrdinalIgnoreCase);
}

public bool ContainsSubPath(string parentPath, string path)
{
if (string.IsNullOrEmpty(parentPath))
Expand All @@ -588,7 +570,7 @@ public bool IsRootPath(string path)
throw new ArgumentNullException("path");
}

var parent = Path.GetDirectoryName(path);
var parent = GetDirectoryName(path);

if (!string.IsNullOrEmpty(parent))
{
Expand All @@ -598,13 +580,28 @@ public bool IsRootPath(string path)
return true;
}

public string GetDirectoryName(string path)
{
if (_sharpCifsFileSystem.IsEnabledForPath(path))
{
return _sharpCifsFileSystem.GetDirectoryName(path);
}

return Path.GetDirectoryName(path);
}

public string NormalizePath(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
}

if (_sharpCifsFileSystem.IsEnabledForPath(path))
{
return _sharpCifsFileSystem.NormalizePath(path);
}

if (path.EndsWith(":\\", StringComparison.OrdinalIgnoreCase))
{
return path;
Expand All @@ -613,6 +610,21 @@ public string NormalizePath(string path)
return path.TrimEnd(GetDirectorySeparatorChar(path));
}

public bool AreEqual(string path1, string path2)
{
if (path1 == null && path2 == null)
{
return true;
}

if (path1 == null || path2 == null)
{
return false;
}

return string.Equals(NormalizePath(path1), NormalizePath(path2), StringComparison.OrdinalIgnoreCase);
}

public string GetFileNameWithoutExtension(FileSystemMetadata info)
{
if (info.IsDirectory)
Expand All @@ -637,11 +649,17 @@ public bool IsPathFile(string path)

// Cannot use Path.IsPathRooted because it returns false under mono when using windows-based paths, e.g. C:\\

if (_sharpCifsFileSystem.IsEnabledForPath(path))
{
return true;
}

if (path.IndexOf("://", StringComparison.OrdinalIgnoreCase) != -1 &&
!path.StartsWith("file://", StringComparison.OrdinalIgnoreCase))
{
return false;
}

return true;

//return Path.IsPathRooted(path);
Expand Down
28 changes: 28 additions & 0 deletions Emby.Common.Implementations/IO/SharpCifsFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,34 @@ public bool IsEnabledForPath(string path)
return path.StartsWith("smb://", StringComparison.OrdinalIgnoreCase) || IsUncPath(path);
}

public string NormalizePath(string path)
{
if (path.StartsWith("smb://", StringComparison.OrdinalIgnoreCase))
{
return path;
}

if (IsUncPath(path))
{
return ConvertUncToSmb(path);
}

return path;
}

public string GetDirectoryName(string path)
{
var separator = GetDirectorySeparatorChar(path);
var result = Path.GetDirectoryName(path);

if (separator == '/')
{
result = result.Replace('\\', '/');
}

return result;
}

public char GetDirectorySeparatorChar(string path)
{
if (path.IndexOf('/') != -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private set
_lastExecutionResult = value;

var path = GetHistoryFilePath();
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));

lock (_lastExecutionResultSyncLock)
{
Expand Down Expand Up @@ -575,7 +575,7 @@ private void SaveTriggers(TaskTriggerInfo[] triggers)
{
var path = GetConfigurationFilePath();

_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));

JsonSerializer.SerializeToFile(triggers, path);
}
Expand Down
2 changes: 1 addition & 1 deletion Emby.Drawing.ImageMagick/ImageMagickEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void TestWebp()
try
{
var tmpPath = Path.Combine(_appPaths.TempDirectory, Guid.NewGuid() + ".webp");
_fileSystem.CreateDirectory(Path.GetDirectoryName(tmpPath));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(tmpPath));

using (var wand = new MagickWand(1, 1, new PixelWand("none", 1)))
{
Expand Down
6 changes: 3 additions & 3 deletions Emby.Drawing.ImageMagick/PlayedIndicatorDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal static string ExtractFont(string name, IApplicationPaths paths, IFileSy

var namespacePath = typeof(PlayedIndicatorDrawer).Namespace + ".fonts." + name;
var tempPath = Path.Combine(paths.TempDirectory, Guid.NewGuid().ToString("N") + ".ttf");
fileSystem.CreateDirectory(Path.GetDirectoryName(tempPath));
fileSystem.CreateDirectory(fileSystem.GetDirectoryName(tempPath));

using (var stream = typeof(PlayedIndicatorDrawer).Assembly.GetManifestResourceStream(namespacePath))
{
Expand All @@ -78,7 +78,7 @@ internal static string ExtractFont(string name, IApplicationPaths paths, IFileSy
}
}

fileSystem.CreateDirectory(Path.GetDirectoryName(filePath));
fileSystem.CreateDirectory(fileSystem.GetDirectoryName(filePath));

try
{
Expand Down Expand Up @@ -108,7 +108,7 @@ internal static async Task<string> DownloadFont(string name, string url, IApplic

}).ConfigureAwait(false);

fileSystem.CreateDirectory(Path.GetDirectoryName(filePath));
fileSystem.CreateDirectory(fileSystem.GetDirectoryName(filePath));

try
{
Expand Down
4 changes: 2 additions & 2 deletions Emby.Drawing.Net/GDIImageEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void CropWhiteSpace(string inputPath, string outputPath)
{
using (var croppedImage = image.CropWhitespace())
{
_fileSystem.CreateDirectory(Path.GetDirectoryName(outputPath));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(outputPath));

using (var outputStream = _fileSystem.GetFileStream(outputPath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, false))
{
Expand Down Expand Up @@ -135,7 +135,7 @@ public void EncodeImage(string inputPath, string cacheFilePath, bool autoOrient,

var outputFormat = GetOutputFormat(originalImage, selectedOutputFormat);

_fileSystem.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(cacheFilePath));

// Save to the cache location
using (var cacheFileStream = _fileSystem.GetFileStream(cacheFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, false))
Expand Down
14 changes: 7 additions & 7 deletions Emby.Drawing/ImageProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ public async Task<Tuple<string, string, DateTime>> ProcessImage(ImageProcessingO
var newWidth = Convert.ToInt32(newSize.Width);
var newHeight = Convert.ToInt32(newSize.Height);

_fileSystem.CreateDirectory(Path.GetDirectoryName(cacheFilePath));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(cacheFilePath));
var tmpPath = Path.ChangeExtension(Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString("N")), Path.GetExtension(cacheFilePath));
_fileSystem.CreateDirectory(Path.GetDirectoryName(tmpPath));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(tmpPath));

_imageEncoder.EncodeImage(originalImagePath, tmpPath, AutoOrient(options.Item), newWidth, newHeight, quality, options, outputFormat);
CopyFile(tmpPath, cacheFilePath);
Expand Down Expand Up @@ -418,9 +418,9 @@ private async Task<Tuple<string, DateTime>> GetWhitespaceCroppedImage(string ori

try
{
_fileSystem.CreateDirectory(Path.GetDirectoryName(croppedImagePath));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(croppedImagePath));
var tmpPath = Path.ChangeExtension(Path.Combine(_appPaths.TempDirectory, Guid.NewGuid().ToString("N")), Path.GetExtension(croppedImagePath));
_fileSystem.CreateDirectory(Path.GetDirectoryName(tmpPath));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(tmpPath));

_imageEncoder.CropWhiteSpace(originalImagePath, tmpPath);
CopyFile(tmpPath, croppedImagePath);
Expand Down Expand Up @@ -592,7 +592,7 @@ private void SaveImageSizeCallback(object state)
try
{
var path = ImageSizeFile;
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
_jsonSerializer.SerializeToFile(_cachedImagedSizes, path);
}
catch (Exception ex)
Expand Down Expand Up @@ -765,10 +765,10 @@ private async Task<string> GetEnhancedImageInternal(string originalImagePath,
return enhancedImagePath;
}

_fileSystem.CreateDirectory(Path.GetDirectoryName(enhancedImagePath));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(enhancedImagePath));

var tmpPath = Path.Combine(_appPaths.TempDirectory, Path.ChangeExtension(Guid.NewGuid().ToString(), Path.GetExtension(enhancedImagePath)));
_fileSystem.CreateDirectory(Path.GetDirectoryName(tmpPath));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(tmpPath));

await ExecuteImageEnhancers(supportedEnhancers, originalImagePath, tmpPath, item, imageType, imageIndex).ConfigureAwait(false);

Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Core/ApplicationHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ private CertificateInfo GetCertificateInfo(bool generateCertificate)
{
if (!FileSystemManager.FileExists(certPath))
{
FileSystemManager.CreateDirectory(Path.GetDirectoryName(certPath));
FileSystemManager.CreateDirectory(FileSystemManager.GetDirectoryName(certPath));

try
{
Expand Down
6 changes: 3 additions & 3 deletions Emby.Server.Core/IO/LibraryMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public void ReportFileSystemChanged(string path)
}

// Go up a level
var parent = Path.GetDirectoryName(i);
var parent = _fileSystem.GetDirectoryName(i);
if (!string.IsNullOrEmpty(parent))
{
if (_fileSystem.AreEqual(parent, path))
Expand All @@ -492,7 +492,7 @@ public void ReportFileSystemChanged(string path)

private void CreateRefresher(string path)
{
var parentPath = Path.GetDirectoryName(path);
var parentPath = _fileSystem.GetDirectoryName(path);

lock (_activeRefreshers)
{
Expand Down Expand Up @@ -521,7 +521,7 @@ private void CreateRefresher(string path)
}

// They are siblings. Rebase the refresher to the parent folder.
if (string.Equals(parentPath, Path.GetDirectoryName(refresher.Path), StringComparison.Ordinal))
if (string.Equals(parentPath, _fileSystem.GetDirectoryName(refresher.Path), StringComparison.Ordinal))
{
refresher.ResetPath(parentPath, path);
return;
Expand Down
4 changes: 2 additions & 2 deletions Emby.Server.Implementations/Channels/ChannelManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private void SaveMediaSources(BaseItem item, List<ChannelMediaInfo> mediaSources
return;
}

_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));

_jsonSerializer.SerializeToFile(mediaSources, path);
}
Expand Down Expand Up @@ -1105,7 +1105,7 @@ private void CacheResponse(object result, string path)
{
try
{
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));

_jsonSerializer.SerializeToFile(result, path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ private async Task OrganizeEpisode(string sourcePath,
_libraryMonitor.ReportFileSystemChangeBeginning(path);

var renameRelatedFiles = !hasRenamedFiles &&
string.Equals(Path.GetDirectoryName(path), Path.GetDirectoryName(result.TargetPath), StringComparison.OrdinalIgnoreCase);
string.Equals(_fileSystem.GetDirectoryName(path), _fileSystem.GetDirectoryName(result.TargetPath), StringComparison.OrdinalIgnoreCase);

if (renameRelatedFiles)
{
Expand Down Expand Up @@ -432,7 +432,7 @@ private void DeleteLibraryFile(string path, bool renameRelatedFiles, string targ

// Now find other files
var originalFilenameWithoutExtension = Path.GetFileNameWithoutExtension(path);
var directory = Path.GetDirectoryName(path);
var directory = _fileSystem.GetDirectoryName(path);

if (!string.IsNullOrWhiteSpace(originalFilenameWithoutExtension) && !string.IsNullOrWhiteSpace(directory))
{
Expand All @@ -445,7 +445,7 @@ private void DeleteLibraryFile(string path, bool renameRelatedFiles, string targ

foreach (var file in files)
{
directory = Path.GetDirectoryName(file);
directory = _fileSystem.GetDirectoryName(file);
var filename = Path.GetFileName(file);

filename = filename.Replace(originalFilenameWithoutExtension, targetFilenameWithoutExtension,
Expand Down Expand Up @@ -499,7 +499,7 @@ private List<string> GetOtherDuplicatePaths(string targetPath,
.Select(i => i.Path)
.ToList();

var folder = Path.GetDirectoryName(targetPath);
var folder = _fileSystem.GetDirectoryName(targetPath);
var targetFileNameWithoutExtension = _fileSystem.GetFileNameWithoutExtension(targetPath);

try
Expand Down Expand Up @@ -529,7 +529,7 @@ private void PerformFileSorting(TvFileOrganizationOptions options, FileOrganizat

_libraryMonitor.ReportFileSystemChangeBeginning(result.TargetPath);

_fileSystem.CreateDirectory(Path.GetDirectoryName(result.TargetPath));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(result.TargetPath));

var targetAlreadyExists = _fileSystem.FileExists(result.TargetPath);

Expand Down
2 changes: 1 addition & 1 deletion Emby.Server.Implementations/IO/FileRefresher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private BaseItem GetAffectedBaseItem(string path)
{
item = LibraryManager.FindByPath(path, null);

path = System.IO.Path.GetDirectoryName(path);
path = _fileSystem.GetDirectoryName(path);
}

if (item != null)
Expand Down
Loading

0 comments on commit 7cc91bb

Please sign in to comment.