mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
fix multiple scan restarts when renaming collection
This commit is contained in:
parent
8792ed9ab0
commit
4b886ea93f
@ -21,44 +21,6 @@ namespace MediaBrowser.Api.Library
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private const string ShortcutFileSearch = "*" + ShortcutFileExtension;
|
private const string ShortcutFileSearch = "*" + ShortcutFileExtension;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Renames the virtual folder.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="name">The name.</param>
|
|
||||||
/// <param name="newName">The new name.</param>
|
|
||||||
/// <param name="user">The user.</param>
|
|
||||||
/// <param name="appPaths">The app paths.</param>
|
|
||||||
/// <exception cref="System.IO.DirectoryNotFoundException">The media collection does not exist</exception>
|
|
||||||
/// <exception cref="System.ArgumentException">There is already a media collection with the name + newPath + .</exception>
|
|
||||||
public static void RenameVirtualFolder(string name, string newName, User user, IServerApplicationPaths appPaths)
|
|
||||||
{
|
|
||||||
var rootFolderPath = user != null ? user.RootFolderPath : appPaths.DefaultUserViewsPath;
|
|
||||||
|
|
||||||
var currentPath = Path.Combine(rootFolderPath, name);
|
|
||||||
var newPath = Path.Combine(rootFolderPath, newName);
|
|
||||||
|
|
||||||
if (!Directory.Exists(currentPath))
|
|
||||||
{
|
|
||||||
throw new DirectoryNotFoundException("The media collection does not exist");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!string.Equals(currentPath, newPath, StringComparison.OrdinalIgnoreCase) && Directory.Exists(newPath))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("There is already a media collection with the name " + newPath + ".");
|
|
||||||
}
|
|
||||||
//Only make a two-phase move when changing capitalization
|
|
||||||
if (string.Equals(currentPath, newPath, StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
//Create an unique name
|
|
||||||
var temporaryName = Guid.NewGuid().ToString();
|
|
||||||
var temporaryPath = Path.Combine(rootFolderPath, temporaryName);
|
|
||||||
Directory.Move(currentPath,temporaryPath);
|
|
||||||
currentPath = temporaryPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
Directory.Move(currentPath, newPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes a shortcut from within a virtual folder, within either the default view or a user view
|
/// Deletes a shortcut from within a virtual folder, within either the default view or a user view
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System.IO;
|
using MediaBrowser.Common.IO;
|
||||||
using MediaBrowser.Common.IO;
|
|
||||||
using MediaBrowser.Controller;
|
using MediaBrowser.Controller;
|
||||||
using MediaBrowser.Controller.IO;
|
using MediaBrowser.Controller.IO;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
@ -8,6 +7,7 @@ using MediaBrowser.Model.Logging;
|
|||||||
using ServiceStack.ServiceHost;
|
using ServiceStack.ServiceHost;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -302,21 +302,50 @@ namespace MediaBrowser.Api.Library
|
|||||||
/// <param name="request">The request.</param>
|
/// <param name="request">The request.</param>
|
||||||
public void Post(RenameVirtualFolder request)
|
public void Post(RenameVirtualFolder request)
|
||||||
{
|
{
|
||||||
_directoryWatchers.Stop();
|
string rootFolderPath;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(request.UserId))
|
if (string.IsNullOrEmpty(request.UserId))
|
||||||
{
|
{
|
||||||
LibraryHelpers.RenameVirtualFolder(request.Name, request.NewName, null, _appPaths);
|
rootFolderPath = _appPaths.DefaultUserViewsPath;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var user = _userManager.GetUserById(new Guid(request.UserId));
|
var user = _userManager.GetUserById(new Guid(request.UserId));
|
||||||
|
|
||||||
LibraryHelpers.RenameVirtualFolder(request.Name, request.NewName, user, _appPaths);
|
rootFolderPath = user.RootFolderPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var currentPath = Path.Combine(rootFolderPath, request.Name);
|
||||||
|
var newPath = Path.Combine(rootFolderPath, request.NewName);
|
||||||
|
|
||||||
|
if (!Directory.Exists(currentPath))
|
||||||
|
{
|
||||||
|
throw new DirectoryNotFoundException("The media collection does not exist");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.Equals(currentPath, newPath, StringComparison.OrdinalIgnoreCase) && Directory.Exists(newPath))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("There is already a media collection with the name " + newPath + ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
_directoryWatchers.Stop();
|
||||||
|
_directoryWatchers.TemporarilyIgnore(currentPath);
|
||||||
|
_directoryWatchers.TemporarilyIgnore(newPath);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Only make a two-phase move when changing capitalization
|
||||||
|
if (string.Equals(currentPath, newPath, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
//Create an unique name
|
||||||
|
var temporaryName = Guid.NewGuid().ToString();
|
||||||
|
var temporaryPath = Path.Combine(rootFolderPath, temporaryName);
|
||||||
|
Directory.Move(currentPath, temporaryPath);
|
||||||
|
currentPath = temporaryPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
Directory.Move(currentPath, newPath);
|
||||||
|
|
||||||
// Need to add a delay here or directory watchers may still pick up the changes
|
// Need to add a delay here or directory watchers may still pick up the changes
|
||||||
var task = Task.Delay(1000);
|
var task = Task.Delay(1000);
|
||||||
// Have to block here to allow exceptions to bubble
|
// Have to block here to allow exceptions to bubble
|
||||||
@ -325,6 +354,8 @@ namespace MediaBrowser.Api.Library
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
_directoryWatchers.Start();
|
_directoryWatchers.Start();
|
||||||
|
_directoryWatchers.RemoveTempIgnore(currentPath);
|
||||||
|
_directoryWatchers.RemoveTempIgnore(newPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.RefreshLibrary)
|
if (request.RefreshLibrary)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user