aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Library
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Api/Library')
-rw-r--r--MediaBrowser.Api/Library/LibraryHelpers.cs6
-rw-r--r--MediaBrowser.Api/Library/LibraryService.cs7
-rw-r--r--MediaBrowser.Api/Library/LibraryStructureService.cs19
3 files changed, 19 insertions, 13 deletions
diff --git a/MediaBrowser.Api/Library/LibraryHelpers.cs b/MediaBrowser.Api/Library/LibraryHelpers.cs
index 0ee28d6fe..5e40ac635 100644
--- a/MediaBrowser.Api/Library/LibraryHelpers.cs
+++ b/MediaBrowser.Api/Library/LibraryHelpers.cs
@@ -33,7 +33,7 @@ namespace MediaBrowser.Api.Library
var rootFolderPath = appPaths.DefaultUserViewsPath;
var path = Path.Combine(rootFolderPath, virtualFolderName);
- if (!Directory.Exists(path))
+ if (!fileSystem.DirectoryExists(path))
{
throw new DirectoryNotFoundException(string.Format("The media collection {0} does not exist", virtualFolderName));
}
@@ -57,7 +57,7 @@ namespace MediaBrowser.Api.Library
/// <exception cref="System.ArgumentException">The path is not valid.</exception>
public static void AddMediaPath(IFileSystem fileSystem, string virtualFolderName, string path, IServerApplicationPaths appPaths)
{
- if (!Directory.Exists(path))
+ if (!fileSystem.DirectoryExists(path))
{
throw new DirectoryNotFoundException("The path does not exist.");
}
@@ -69,7 +69,7 @@ namespace MediaBrowser.Api.Library
var lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension);
- while (File.Exists(lnk))
+ while (fileSystem.FileExists(lnk))
{
shortcutFilename += "1";
lnk = Path.Combine(virtualFolderPath, shortcutFilename + ShortcutFileExtension);
diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs
index 49dd121ba..eb1cd6084 100644
--- a/MediaBrowser.Api/Library/LibraryService.cs
+++ b/MediaBrowser.Api/Library/LibraryService.cs
@@ -27,6 +27,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using MediaBrowser.Common.IO;
namespace MediaBrowser.Api.Library
{
@@ -282,12 +283,13 @@ namespace MediaBrowser.Api.Library
private readonly IChannelManager _channelManager;
private readonly ITVSeriesManager _tvManager;
private readonly ILibraryMonitor _libraryMonitor;
+ private readonly IFileSystem _fileSystem;
/// <summary>
/// Initializes a new instance of the <see cref="LibraryService" /> class.
/// </summary>
public LibraryService(IItemRepository itemRepo, ILibraryManager libraryManager, IUserManager userManager,
- IDtoService dtoService, IUserDataManager userDataManager, IAuthorizationContext authContext, IActivityManager activityManager, ILocalizationManager localization, ILiveTvManager liveTv, IChannelManager channelManager, ITVSeriesManager tvManager, ILibraryMonitor libraryMonitor)
+ IDtoService dtoService, IUserDataManager userDataManager, IAuthorizationContext authContext, IActivityManager activityManager, ILocalizationManager localization, ILiveTvManager liveTv, IChannelManager channelManager, ITVSeriesManager tvManager, ILibraryMonitor libraryMonitor, IFileSystem fileSystem)
{
_itemRepo = itemRepo;
_libraryManager = libraryManager;
@@ -301,6 +303,7 @@ namespace MediaBrowser.Api.Library
_channelManager = channelManager;
_tvManager = tvManager;
_libraryMonitor = libraryMonitor;
+ _fileSystem = fileSystem;
}
public object Get(GetSimilarItems request)
@@ -557,7 +560,7 @@ namespace MediaBrowser.Api.Library
{
throw new ArgumentException("This command cannot be used for remote or virtual items.");
}
- if (Directory.Exists(item.Path))
+ if (_fileSystem.DirectoryExists(item.Path))
{
throw new ArgumentException("This command cannot be used for directories.");
}
diff --git a/MediaBrowser.Api/Library/LibraryStructureService.cs b/MediaBrowser.Api/Library/LibraryStructureService.cs
index f5fe921ce..c8731637c 100644
--- a/MediaBrowser.Api/Library/LibraryStructureService.cs
+++ b/MediaBrowser.Api/Library/LibraryStructureService.cs
@@ -195,7 +195,7 @@ namespace MediaBrowser.Api.Library
var virtualFolderPath = Path.Combine(rootFolderPath, name);
- if (Directory.Exists(virtualFolderPath))
+ if (_fileSystem.DirectoryExists(virtualFolderPath))
{
throw new ArgumentException("There is already a media collection with the name " + name + ".");
}
@@ -204,13 +204,16 @@ namespace MediaBrowser.Api.Library
try
{
- Directory.CreateDirectory(virtualFolderPath);
+ _fileSystem.CreateDirectory(virtualFolderPath);
if (!string.IsNullOrEmpty(request.CollectionType))
{
var path = Path.Combine(virtualFolderPath, request.CollectionType + ".collection");
- File.Create(path);
+ using (File.Create(path))
+ {
+
+ }
}
}
finally
@@ -256,12 +259,12 @@ namespace MediaBrowser.Api.Library
var currentPath = Path.Combine(rootFolderPath, request.Name);
var newPath = Path.Combine(rootFolderPath, request.NewName);
- if (!Directory.Exists(currentPath))
+ if (!_fileSystem.DirectoryExists(currentPath))
{
throw new DirectoryNotFoundException("The media collection does not exist");
}
- if (!string.Equals(currentPath, newPath, StringComparison.OrdinalIgnoreCase) && Directory.Exists(newPath))
+ if (!string.Equals(currentPath, newPath, StringComparison.OrdinalIgnoreCase) && _fileSystem.DirectoryExists(newPath))
{
throw new ArgumentException("There is already a media collection with the name " + newPath + ".");
}
@@ -276,11 +279,11 @@ namespace MediaBrowser.Api.Library
//Create an unique name
var temporaryName = Guid.NewGuid().ToString();
var temporaryPath = Path.Combine(rootFolderPath, temporaryName);
- Directory.Move(currentPath, temporaryPath);
+ _fileSystem.MoveDirectory(currentPath, temporaryPath);
currentPath = temporaryPath;
}
- Directory.Move(currentPath, newPath);
+ _fileSystem.MoveDirectory(currentPath, newPath);
}
finally
{
@@ -319,7 +322,7 @@ namespace MediaBrowser.Api.Library
var path = Path.Combine(rootFolderPath, request.Name);
- if (!Directory.Exists(path))
+ if (!_fileSystem.DirectoryExists(path))
{
throw new DirectoryNotFoundException("The media folder does not exist");
}