add error handling when resolving shortcuts

This commit is contained in:
Luke Pulverenti 2015-11-30 22:54:24 -05:00
parent ae76e1c725
commit 1a1fbec334
1 changed files with 27 additions and 20 deletions

View File

@ -26,12 +26,12 @@ namespace MediaBrowser.Controller.IO
/// <param name="resolveShortcuts">if set to <c>true</c> [resolve shortcuts].</param> /// <param name="resolveShortcuts">if set to <c>true</c> [resolve shortcuts].</param>
/// <returns>Dictionary{System.StringFileSystemInfo}.</returns> /// <returns>Dictionary{System.StringFileSystemInfo}.</returns>
/// <exception cref="System.ArgumentNullException">path</exception> /// <exception cref="System.ArgumentNullException">path</exception>
public static Dictionary<string, FileSystemMetadata> GetFilteredFileSystemEntries(IDirectoryService directoryService, public static Dictionary<string, FileSystemMetadata> GetFilteredFileSystemEntries(IDirectoryService directoryService,
string path, string path,
IFileSystem fileSystem, IFileSystem fileSystem,
ILogger logger, ILogger logger,
ItemResolveArgs args, ItemResolveArgs args,
int flattenFolderDepth = 0, int flattenFolderDepth = 0,
bool resolveShortcuts = true) bool resolveShortcuts = true)
{ {
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(path))
@ -60,22 +60,29 @@ namespace MediaBrowser.Controller.IO
if (resolveShortcuts && fileSystem.IsShortcut(fullName)) if (resolveShortcuts && fileSystem.IsShortcut(fullName))
{ {
var newPath = fileSystem.ResolveShortcut(fullName); try
if (string.IsNullOrWhiteSpace(newPath))
{ {
//invalid shortcut - could be old or target could just be unavailable var newPath = fileSystem.ResolveShortcut(fullName);
logger.Warn("Encountered invalid shortcut: " + fullName);
continue; if (string.IsNullOrWhiteSpace(newPath))
{
//invalid shortcut - could be old or target could just be unavailable
logger.Warn("Encountered invalid shortcut: " + fullName);
continue;
}
// Don't check if it exists here because that could return false for network shares.
var data = fileSystem.GetDirectoryInfo(newPath);
// add to our physical locations
args.AddAdditionalLocation(newPath);
dict[newPath] = data;
}
catch (Exception ex)
{
logger.ErrorException("Error resolving shortcut from {0}", ex, fullName);
} }
// Don't check if it exists here because that could return false for network shares.
var data = fileSystem.GetDirectoryInfo(newPath);
// add to our physical locations
args.AddAdditionalLocation(newPath);
dict[newPath] = data;
} }
else if (flattenFolderDepth > 0 && isDirectory) else if (flattenFolderDepth > 0 && isDirectory)
{ {