From ff5e5497c50ee666f80140b4116e40cf1d441363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Mon, 27 May 2024 07:39:17 +0200 Subject: [PATCH] Fix recursive copy not working --- .../FileTime.Core.Command/Copy/CopyCommand.cs | 7 +++++-- .../Copy/CopyCommandFactory.cs | 4 ++++ .../FileTime.Core.Command/Copy/CopyStrategy.cs | 14 ++++++++++---- .../Copy/CopyStrategyFactory.cs | 18 ++++++++++++++++++ .../Startup.cs | 1 + .../LocalContentProvider.cs | 8 +++++++- 6 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 src/Core/FileTime.Core.Command/Copy/CopyStrategyFactory.cs diff --git a/src/Core/FileTime.Core.Command/Copy/CopyCommand.cs b/src/Core/FileTime.Core.Command/Copy/CopyCommand.cs index 5916a56..511f0c6 100644 --- a/src/Core/FileTime.Core.Command/Copy/CopyCommand.cs +++ b/src/Core/FileTime.Core.Command/Copy/CopyCommand.cs @@ -11,6 +11,7 @@ public class CopyCommand : CommandBase, ITransportationCommand { private readonly ITimelessContentProvider _timelessContentProvider; private readonly ICommandSchedulerNotifier _commandSchedulerNotifier; + private readonly CopyStrategyFactory _copyStrategyFactory; private readonly ILogger _logger; private readonly CancellationTokenSource _cancellationTokenSource = new(); @@ -29,7 +30,8 @@ public class CopyCommand : CommandBase, ITransportationCommand internal CopyCommand( ITimelessContentProvider timelessContentProvider, - ICommandSchedulerNotifier commandSchedulerNotifier, + ICommandSchedulerNotifier commandSchedulerNotifier, + CopyStrategyFactory copyStrategyFactory, ILogger logger, IReadOnlyCollection 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); diff --git a/src/Core/FileTime.Core.Command/Copy/CopyCommandFactory.cs b/src/Core/FileTime.Core.Command/Copy/CopyCommandFactory.cs index 1f180c5..f20b890 100644 --- a/src/Core/FileTime.Core.Command/Copy/CopyCommandFactory.cs +++ b/src/Core/FileTime.Core.Command/Copy/CopyCommandFactory.cs @@ -9,16 +9,19 @@ public class CopyCommandFactory : ITransportationCommandFactory { 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 => new( _timelessContentProvider, _commandSchedulerNotifier, + _copyStrategyFactory, _serviceProvider.GetRequiredService>(), sources, mode, diff --git a/src/Core/FileTime.Core.Command/Copy/CopyStrategy.cs b/src/Core/FileTime.Core.Command/Copy/CopyStrategy.cs index 3c99c6f..5a398af 100644 --- a/src/Core/FileTime.Core.Command/Copy/CopyStrategy.cs +++ b/src/Core/FileTime.Core.Command/Copy/CopyStrategy.cs @@ -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)); } -} \ No newline at end of file +} diff --git a/src/Core/FileTime.Core.Command/Copy/CopyStrategyFactory.cs b/src/Core/FileTime.Core.Command/Copy/CopyStrategyFactory.cs new file mode 100644 index 0000000..da5b3b9 --- /dev/null +++ b/src/Core/FileTime.Core.Command/Copy/CopyStrategyFactory.cs @@ -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 operationProgresses, Func refreshContainer) + { + return new CopyStrategy(copy, new CopyStrategyParam(operationProgresses, refreshContainer), _contentAccessorFactory); + } +} \ No newline at end of file diff --git a/src/Core/FileTime.Core.Extensions.DependencyInjection/Startup.cs b/src/Core/FileTime.Core.Extensions.DependencyInjection/Startup.cs index fbd1002..65dbad0 100644 --- a/src/Core/FileTime.Core.Extensions.DependencyInjection/Startup.cs +++ b/src/Core/FileTime.Core.Extensions.DependencyInjection/Startup.cs @@ -73,6 +73,7 @@ public static class Startup private static IServiceCollection AddCommandFactories(this IServiceCollection serviceCollection) => serviceCollection .AddSingleton() + .AddSingleton() .AddSingleton(); diff --git a/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs b/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs index d8a4b7d..89beebe 100644 --- a/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs +++ b/src/Providers/FileTime.Providers.Local/LocalContentProvider.cs @@ -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() ); + 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; }