Fix recursive copy not working

This commit is contained in:
2024-05-27 07:39:17 +02:00
parent 51a81ddf53
commit ff5e5497c5
6 changed files with 45 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ public class CopyCommand : CommandBase, ITransportationCommand
{
private readonly ITimelessContentProvider _timelessContentProvider;
private readonly ICommandSchedulerNotifier _commandSchedulerNotifier;
private readonly CopyStrategyFactory _copyStrategyFactory;
private readonly ILogger<CopyCommand> _logger;
private readonly CancellationTokenSource _cancellationTokenSource = new();
@@ -30,6 +31,7 @@ public class CopyCommand : CommandBase, ITransportationCommand
internal CopyCommand(
ITimelessContentProvider timelessContentProvider,
ICommandSchedulerNotifier commandSchedulerNotifier,
CopyStrategyFactory copyStrategyFactory,
ILogger<CopyCommand> logger,
IReadOnlyCollection<FullName> sources,
TransportMode mode,
@@ -42,6 +44,7 @@ public class CopyCommand : CommandBase, ITransportationCommand
_timelessContentProvider = timelessContentProvider;
_commandSchedulerNotifier = commandSchedulerNotifier;
_copyStrategyFactory = copyStrategyFactory;
_logger = logger;
_currentOperationProgress
.Map(p =>
@@ -105,7 +108,7 @@ public class CopyCommand : CommandBase, ITransportationCommand
await CalculateProgressAsync(currentTime);
var copyOperation = new CopyStrategy(copy, new CopyStrategyParam(_operationProgresses, _commandSchedulerNotifier.RefreshContainer));
var copyOperation = _copyStrategyFactory.CreateCopyStrategy(copy, _operationProgresses, _commandSchedulerNotifier.RefreshContainer);
var resolvedTarget = await _timelessContentProvider.GetItemByFullNameAsync(Target, currentTime);

View File

@@ -9,16 +9,19 @@ public class CopyCommandFactory : ITransportationCommandFactory<CopyCommand>
{
private readonly ITimelessContentProvider _timelessContentProvider;
private readonly ICommandSchedulerNotifier _commandSchedulerNotifier;
private readonly CopyStrategyFactory _copyStrategyFactory;
private readonly IServiceProvider _serviceProvider;
public CopyCommandFactory(
ITimelessContentProvider timelessContentProvider,
ICommandSchedulerNotifier commandSchedulerNotifier,
CopyStrategyFactory copyStrategyFactory,
IServiceProvider serviceProvider)
{
_timelessContentProvider = timelessContentProvider;
_commandSchedulerNotifier = commandSchedulerNotifier;
_copyStrategyFactory = copyStrategyFactory;
_serviceProvider = serviceProvider;
}
@@ -29,6 +32,7 @@ public class CopyCommandFactory : ITransportationCommandFactory<CopyCommand>
=> new(
_timelessContentProvider,
_commandSchedulerNotifier,
_copyStrategyFactory,
_serviceProvider.GetRequiredService<ILogger<CopyCommand>>(),
sources,
mode,

View File

@@ -1,3 +1,4 @@
using FileTime.Core.ContentAccess;
using FileTime.Core.Models;
using FileTime.Core.Timeline;
@@ -7,11 +8,13 @@ public class CopyStrategy : ICopyStrategy
{
private readonly CopyFunc _copy;
private readonly CopyStrategyParam _copyStrategyParam;
private readonly IContentAccessorFactory _contentAccessorFactory;
public CopyStrategy(CopyFunc copy, CopyStrategyParam copyStrategyParam)
public CopyStrategy(CopyFunc copy, CopyStrategyParam copyStrategyParam, IContentAccessorFactory contentAccessorFactory)
{
_copy = copy;
_copyStrategyParam = copyStrategyParam;
_contentAccessorFactory = contentAccessorFactory;
}
public async Task ContainerCopyDoneAsync(AbsolutePath containerPath)
@@ -33,11 +36,14 @@ public class CopyStrategy : ICopyStrategy
}
if (to.Path.GetParent() is { } parent)
{
await _copyStrategyParam.RefreshContainerAsync(parent);
}
}
public Task CreateContainerAsync(IContainer target, string name, PointInTime currentTime)
public async Task CreateContainerAsync(IContainer target, string name, PointInTime currentTime)
{
throw new NotImplementedException();
var itemCreator = _contentAccessorFactory.GetItemCreator(target.Provider);
await itemCreator.CreateContainerAsync(target.Provider, target.FullName!.GetChild(name));
}
}

View File

@@ -0,0 +1,18 @@
using FileTime.Core.ContentAccess;
using FileTime.Core.Models;
namespace FileTime.Core.Command.Copy;
public class CopyStrategyFactory
{
private readonly IContentAccessorFactory _contentAccessorFactory;
public CopyStrategyFactory(IContentAccessorFactory contentAccessorFactory)
{
_contentAccessorFactory = contentAccessorFactory;
}
public ICopyStrategy CreateCopyStrategy(CopyFunc copy, List<OperationProgress> operationProgresses, Func<FullName, Task> refreshContainer)
{
return new CopyStrategy(copy, new CopyStrategyParam(operationProgresses, refreshContainer), _contentAccessorFactory);
}
}

View File

@@ -73,6 +73,7 @@ public static class Startup
private static IServiceCollection AddCommandFactories(this IServiceCollection serviceCollection) =>
serviceCollection
.AddSingleton<CopyCommandFactory>()
.AddSingleton<CopyStrategyFactory>()
.AddSingleton<MoveCommandFactory>();

View File

@@ -220,7 +220,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
parentFullName,
AbsolutePathType.Container);
return new Container(
var container = new Container(
name,
name,
fullName,
@@ -240,6 +240,8 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
new ExtensionCollection().AsReadOnly(),
new ObservableCollection<AbsolutePath>()
);
container.StopLoading();
return container;
}
private IItem CreateEmptyElement(NativePath nativePath)
@@ -302,6 +304,10 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
{
Task.Run(async () => await LoadChildren(container, directoryInfo, children, pointInTime, exceptions));
}
else
{
container.StopLoading();
}
return container;
}