mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-21 09:34:44 +01:00
rework image extraction settings
This commit is contained in:
@@ -408,6 +408,83 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
LibraryItemsCache.AddOrUpdate(item.Id, item, delegate { return item; });
|
||||
}
|
||||
|
||||
public async Task DeleteItem(BaseItem item)
|
||||
{
|
||||
var parent = item.Parent;
|
||||
|
||||
var locationType = item.LocationType;
|
||||
|
||||
var children = item.IsFolder
|
||||
? ((Folder)item).RecursiveChildren.ToList()
|
||||
: new List<BaseItem>();
|
||||
|
||||
foreach (var metadataPath in GetMetadataPaths(item, children))
|
||||
{
|
||||
_logger.Debug("Deleting path {0}", metadataPath);
|
||||
|
||||
try
|
||||
{
|
||||
Directory.Delete(metadataPath, true);
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error deleting {0}", ex, metadataPath);
|
||||
}
|
||||
}
|
||||
|
||||
if (locationType == LocationType.FileSystem || locationType == LocationType.Offline)
|
||||
{
|
||||
foreach (var path in item.GetDeletePaths().ToList())
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
_logger.Debug("Deleting path {0}", path);
|
||||
Directory.Delete(path, true);
|
||||
}
|
||||
else if (File.Exists(path))
|
||||
{
|
||||
_logger.Debug("Deleting path {0}", path);
|
||||
File.Delete(path);
|
||||
}
|
||||
}
|
||||
|
||||
if (parent != null)
|
||||
{
|
||||
await parent.ValidateChildren(new Progress<double>(), CancellationToken.None)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
else if (parent != null)
|
||||
{
|
||||
await parent.RemoveChild(item, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Don't know how to delete " + item.Name);
|
||||
}
|
||||
|
||||
foreach (var child in children)
|
||||
{
|
||||
await ItemRepository.DeleteItem(child.Id, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetMetadataPaths(BaseItem item, IEnumerable<BaseItem> children)
|
||||
{
|
||||
var list = new List<string>
|
||||
{
|
||||
ConfigurationManager.ApplicationPaths.GetInternalMetadataPath(item.Id)
|
||||
};
|
||||
|
||||
list.AddRange(children.Select(i => ConfigurationManager.ApplicationPaths.GetInternalMetadataPath(i.Id)));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the item.
|
||||
/// </summary>
|
||||
|
||||
@@ -61,6 +61,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
|
||||
private IDbCommand _deleteChildrenCommand;
|
||||
private IDbCommand _saveChildrenCommand;
|
||||
private IDbCommand _deleteItemCommand;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
|
||||
@@ -156,6 +157,10 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
_deleteChildrenCommand.CommandText = "delete from ChildrenIds where ParentId=@ParentId";
|
||||
_deleteChildrenCommand.Parameters.Add(_deleteChildrenCommand, "@ParentId");
|
||||
|
||||
_deleteItemCommand = _connection.CreateCommand();
|
||||
_deleteItemCommand.CommandText = "delete from TypedBaseItems where guid=@Id";
|
||||
_deleteItemCommand.Parameters.Add(_deleteItemCommand, "@Id");
|
||||
|
||||
_saveChildrenCommand = _connection.CreateCommand();
|
||||
_saveChildrenCommand.CommandText = "replace into ChildrenIds (ParentId, ItemId) values (@ParentId, @ItemId)";
|
||||
_saveChildrenCommand.Parameters.Add(_saveChildrenCommand, "@ParentId");
|
||||
@@ -463,6 +468,64 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteItem(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
if (id == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
try
|
||||
{
|
||||
transaction = _connection.BeginTransaction();
|
||||
|
||||
// First delete children
|
||||
_deleteChildrenCommand.GetParameter(0).Value = id;
|
||||
_deleteChildrenCommand.Transaction = transaction;
|
||||
_deleteChildrenCommand.ExecuteNonQuery();
|
||||
|
||||
// Delete the item
|
||||
_deleteItemCommand.GetParameter(0).Value = id;
|
||||
_deleteItemCommand.Transaction = transaction;
|
||||
_deleteItemCommand.ExecuteNonQuery();
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.ErrorException("Failed to save children:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Rollback();
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (transaction != null)
|
||||
{
|
||||
transaction.Dispose();
|
||||
}
|
||||
|
||||
_writeLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SaveChildren(Guid parentId, IEnumerable<Guid> children, CancellationToken cancellationToken)
|
||||
{
|
||||
if (parentId == Guid.Empty)
|
||||
@@ -475,8 +538,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
throw new ArgumentNullException("children");
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
Reference in New Issue
Block a user