mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 11:34:57 +02:00
additional fixes for #305
This commit is contained in:
parent
7a5ba39603
commit
b43444c1df
2 changed files with 29 additions and 3 deletions
|
@ -175,7 +175,16 @@ namespace MediaBrowser.Api.Library
|
|||
{
|
||||
var duplicate = Directory.EnumerateFiles(appPaths.RootFolderPath, "*.lnk", SearchOption.AllDirectories)
|
||||
.Select(FileSystem.ResolveShortcut)
|
||||
.FirstOrDefault(p => !IsNewPathValid(mediaPath, p));
|
||||
.FirstOrDefault(p => !IsNewPathValid(mediaPath, p, false));
|
||||
|
||||
if (!string.IsNullOrEmpty(duplicate))
|
||||
{
|
||||
throw new ArgumentException(string.Format("The path cannot be added to the library because {0} already exists.", duplicate));
|
||||
}
|
||||
|
||||
duplicate = Directory.EnumerateFiles(currentViewRootFolderPath, "*.lnk", SearchOption.AllDirectories)
|
||||
.Select(FileSystem.ResolveShortcut)
|
||||
.FirstOrDefault(p => !IsNewPathValid(mediaPath, p, true));
|
||||
|
||||
if (!string.IsNullOrEmpty(duplicate))
|
||||
{
|
||||
|
@ -198,11 +207,13 @@ namespace MediaBrowser.Api.Library
|
|||
/// </summary>
|
||||
/// <param name="newPath">The new path.</param>
|
||||
/// <param name="existingPath">The existing path.</param>
|
||||
/// <param name="enforceSubPathRestriction">if set to <c>true</c> [enforce sub path restriction].</param>
|
||||
/// <returns><c>true</c> if [is new path valid] [the specified new path]; otherwise, <c>false</c>.</returns>
|
||||
private static bool IsNewPathValid(string newPath, string existingPath)
|
||||
private static bool IsNewPathValid(string newPath, string existingPath, bool enforceSubPathRestriction)
|
||||
{
|
||||
// Example: D:\Movies is the existing path
|
||||
// D:\ cannot be added
|
||||
// Neither can D:\Movies\Kids
|
||||
// A D:\Movies duplicate is ok here since that will be caught later
|
||||
|
||||
if (newPath.Equals(existingPath, StringComparison.OrdinalIgnoreCase))
|
||||
|
@ -210,6 +221,12 @@ namespace MediaBrowser.Api.Library
|
|||
return true;
|
||||
}
|
||||
|
||||
// Validate the D:\Movies\Kids scenario
|
||||
if (enforceSubPathRestriction && newPath.StartsWith(existingPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate the D:\ scenario
|
||||
if (existingPath.StartsWith(newPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@ using MediaBrowser.Controller.Library;
|
|||
using MediaBrowser.Controller.Plugins;
|
||||
using MediaBrowser.Controller.Session;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MoreLinq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
@ -22,6 +23,7 @@ namespace MediaBrowser.ServerApplication.EntryPoints
|
|||
private readonly ISessionManager _sessionManager;
|
||||
private readonly IServerManager _serverManager;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// The _library changed sync lock
|
||||
|
@ -195,8 +197,15 @@ namespace MediaBrowser.ServerApplication.EntryPoints
|
|||
var id = userId;
|
||||
var webSockets = currentSessions.Where(u => u.UserId.HasValue && u.UserId.Value == id).SelectMany(i => i.WebSockets).ToList();
|
||||
|
||||
try
|
||||
{
|
||||
await _serverManager.SendWebSocketMessageAsync("LibraryChanged", () => GetLibraryUpdateInfo(itemsAdded, itemsUpdated, itemsRemoved, foldersAddedTo, foldersRemovedFrom, id), webSockets, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error sending LibraryChanged message", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in a new issue