From 6ad61592b302768aff033543dc2af22f2ea2952a Mon Sep 17 00:00:00 2001 From: Cyprien Autexier <2660262+sandorfr@users.noreply.github.com> Date: Tue, 30 Nov 2021 18:51:39 +1100 Subject: [PATCH] delete extended properties on file delete --- .../Internal/ExtendedPropertiesProvider.cs | 11 +++++++++++ .../IExtendedPropertiesProvider.cs | 2 ++ .../Internal/FileSystemFileReference.cs | 8 ++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/GeekLearning.Storage.FileSystem.ExtendedProperties.FileSystem/Internal/ExtendedPropertiesProvider.cs b/src/GeekLearning.Storage.FileSystem.ExtendedProperties.FileSystem/Internal/ExtendedPropertiesProvider.cs index 01e7a14..b1c4781 100644 --- a/src/GeekLearning.Storage.FileSystem.ExtendedProperties.FileSystem/Internal/ExtendedPropertiesProvider.cs +++ b/src/GeekLearning.Storage.FileSystem.ExtendedProperties.FileSystem/Internal/ExtendedPropertiesProvider.cs @@ -55,5 +55,16 @@ private void EnsurePathExists(string path) Directory.CreateDirectory(directoryPath); } } + + public Task DeleteExtendedPropertiesAsync(string storeAbsolutePath, IPrivateFileReference file) + { + var extendedPropertiesPath = this.GetExtendedPropertiesPath(storeAbsolutePath, file); + if (File.Exists(extendedPropertiesPath)) + { + File.Delete(extendedPropertiesPath); + } + + return Task.FromResult(0); + } } } diff --git a/src/GeekLearning.Storage.FileSystem/IExtendedPropertiesProvider.cs b/src/GeekLearning.Storage.FileSystem/IExtendedPropertiesProvider.cs index 5785103..bfadde5 100644 --- a/src/GeekLearning.Storage.FileSystem/IExtendedPropertiesProvider.cs +++ b/src/GeekLearning.Storage.FileSystem/IExtendedPropertiesProvider.cs @@ -7,5 +7,7 @@ public interface IExtendedPropertiesProvider ValueTask GetExtendedPropertiesAsync(string storeAbsolutePath, IPrivateFileReference file); Task SaveExtendedPropertiesAsync(string storeAbsolutePath, IPrivateFileReference file, Internal.FileExtendedProperties extendedProperties); + + Task DeleteExtendedPropertiesAsync(string storeAbsolutePath, IPrivateFileReference file); } } diff --git a/src/GeekLearning.Storage.FileSystem/Internal/FileSystemFileReference.cs b/src/GeekLearning.Storage.FileSystem/Internal/FileSystemFileReference.cs index d038472..4efb485 100644 --- a/src/GeekLearning.Storage.FileSystem/Internal/FileSystemFileReference.cs +++ b/src/GeekLearning.Storage.FileSystem/Internal/FileSystemFileReference.cs @@ -56,10 +56,14 @@ public FileSystemFileReference( public IFileProperties Properties => this.propertiesLazy.Value; - public Task DeleteAsync() + public async Task DeleteAsync() { File.Delete(this.FileSystemPath); - return Task.FromResult(true); + + if (extendedPropertiesProvider != null) + { + await extendedPropertiesProvider.DeleteExtendedPropertiesAsync(this.FileSystemPath, this); + } } public ValueTask ReadAllBytesAsync()