fixes #305 - Multiple collections

This commit is contained in:
Luke Pulverenti 2013-05-24 13:48:48 -04:00
parent 398b658dbe
commit 7a5ba39603
4 changed files with 31 additions and 13 deletions

View File

@ -203,7 +203,6 @@ namespace MediaBrowser.Api.Library
{ {
// Example: D:\Movies is the existing path // Example: D:\Movies is the existing path
// D:\ cannot be added // D:\ cannot be added
// Neither can D:\Movies\Kids
// A D:\Movies duplicate is ok here since that will be caught later // A D:\Movies duplicate is ok here since that will be caught later
if (newPath.Equals(existingPath, StringComparison.OrdinalIgnoreCase)) if (newPath.Equals(existingPath, StringComparison.OrdinalIgnoreCase))
@ -211,12 +210,6 @@ namespace MediaBrowser.Api.Library
return true; return true;
} }
// Validate the D:\Movies\Kids scenario
if (newPath.StartsWith(existingPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
{
return false;
}
// Validate the D:\ scenario // Validate the D:\ scenario
if (existingPath.StartsWith(newPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)) if (existingPath.StartsWith(newPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
{ {

View File

@ -384,6 +384,18 @@ namespace MediaBrowser.Controller.Entities
var flattenFolderDepth = isPhysicalRoot ? 2 : 0; var flattenFolderDepth = isPhysicalRoot ? 2 : 0;
args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, Logger, flattenFolderDepth: flattenFolderDepth, args: args, resolveShortcuts: isPhysicalRoot || args.IsVf); args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, Logger, flattenFolderDepth: flattenFolderDepth, args: args, resolveShortcuts: isPhysicalRoot || args.IsVf);
// Need to remove subpaths that may have been resolved from shortcuts
// Example: if \\server\movies exists, then strip out \\server\movies\action
if (isPhysicalRoot)
{
var paths = args.FileSystemDictionary.Keys.ToList();
foreach (var subPath in paths.Where(subPath => paths.Any(i => subPath.StartsWith(i.TrimEnd(System.IO.Path.DirectorySeparatorChar) + System.IO.Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))))
{
args.FileSystemDictionary.Remove(subPath);
}
}
} }
//update our dates //update our dates

View File

@ -1,5 +1,4 @@
using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Extensions;
using MediaBrowser.Model.Entities;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
@ -74,23 +73,25 @@ namespace MediaBrowser.Controller.Entities
{ {
get get
{ {
IEnumerable<Guid> folderIds; Dictionary<Guid,Guid> folderIds;
try try
{ {
// Accessing ResolveArgs could involve file system access // Accessing ResolveArgs could involve file system access
folderIds = ResolveArgs.PhysicalLocations.Select(f => (f.GetMBId(typeof(Folder)))); folderIds = ResolveArgs.PhysicalLocations
.Select(f => (f.GetMBId(typeof(Folder))))
.ToDictionary(i => i);
} }
catch (IOException ex) catch (IOException ex)
{ {
Logger.ErrorException("Error creating FolderIds for {0}", ex, Path); Logger.ErrorException("Error creating FolderIds for {0}", ex, Path);
folderIds = new Guid[] {}; folderIds = new Dictionary<Guid, Guid>();
} }
var ourChildren = var ourChildren =
LibraryManager.RootFolder.Children.OfType<Folder>() LibraryManager.RootFolder.RecursiveChildren.OfType<Folder>()
.Where(i => folderIds.Contains(i.Id)) .Where(i => folderIds.ContainsKey(i.Id))
.SelectMany(c => c.Children); .SelectMany(c => c.Children);
return new ConcurrentDictionary<Guid,BaseItem>(ourChildren.ToDictionary(i => i.Id)); return new ConcurrentDictionary<Guid,BaseItem>(ourChildren.ToDictionary(i => i.Id));

View File

@ -430,6 +430,18 @@ namespace MediaBrowser.Server.Implementations.Library
var flattenFolderDepth = isPhysicalRoot ? 2 : 0; var flattenFolderDepth = isPhysicalRoot ? 2 : 0;
args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, _logger, flattenFolderDepth: flattenFolderDepth, args: args, resolveShortcuts: isPhysicalRoot || args.IsVf); args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, _logger, flattenFolderDepth: flattenFolderDepth, args: args, resolveShortcuts: isPhysicalRoot || args.IsVf);
// Need to remove subpaths that may have been resolved from shortcuts
// Example: if \\server\movies exists, then strip out \\server\movies\action
if (isPhysicalRoot)
{
var paths = args.FileSystemDictionary.Keys.ToList();
foreach (var subPath in paths.Where(subPath => paths.Any(i => subPath.StartsWith(i.TrimEnd(System.IO.Path.DirectorySeparatorChar) + System.IO.Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))))
{
args.FileSystemDictionary.Remove(subPath);
}
}
} }
// Check to see if we should resolve based on our contents // Check to see if we should resolve based on our contents