From 6d3665bf8cb5bf63daa0261a02be016c1107e57f Mon Sep 17 00:00:00 2001 From: AnakinRaW Date: Sun, 7 Apr 2024 18:19:41 +0200 Subject: [PATCH] fix directory copier is not recursive --- .../src/DirectoryCopier.cs | 2 +- .../src/Extensions/FileExtensions.cs | 57 +++++++++++++- .../test/DirectoryCopierTest.cs | 14 +++- .../test/DirectoryInfoExtensionsTest.cs | 76 ++++++++++++++----- .../test/FileInfoExtensionsTest.cs | 53 ++++++++++++- version.json | 2 +- 6 files changed, 176 insertions(+), 28 deletions(-) diff --git a/src/CommonUtilities.FileSystem/src/DirectoryCopier.cs b/src/CommonUtilities.FileSystem/src/DirectoryCopier.cs index 0af4180..a57b505 100644 --- a/src/CommonUtilities.FileSystem/src/DirectoryCopier.cs +++ b/src/CommonUtilities.FileSystem/src/DirectoryCopier.cs @@ -218,7 +218,7 @@ private bool CopyOrMoveDirectory( private IEnumerable GetFiles(string source, string destination, bool isMove, Predicate? fileFilter) { - foreach (var file in _fileSystem.Directory.GetFiles(source, "*", SearchOption.TopDirectoryOnly)) + foreach (var file in _fileSystem.Directory.GetFiles(source, "*", SearchOption.AllDirectories)) { if (fileFilter is not null && !fileFilter(file)) continue; diff --git a/src/CommonUtilities.FileSystem/src/Extensions/FileExtensions.cs b/src/CommonUtilities.FileSystem/src/Extensions/FileExtensions.cs index b39f4f3..8303822 100644 --- a/src/CommonUtilities.FileSystem/src/Extensions/FileExtensions.cs +++ b/src/CommonUtilities.FileSystem/src/Extensions/FileExtensions.cs @@ -187,7 +187,6 @@ public static void DeleteIfInTemp(this IFile _, string file) /// Number of retry attempts tempts until the operation fails. /// Delay time in ms between each new attempt. /// Callback which gets always triggered if an attempt failed. - /// if the operation failed. otherwise. public static void DeleteWithRetry(this IFileInfo file, int retryCount = 2, int retryDelay = 500, Func? errorAction = null) { if (file == null) @@ -204,7 +203,6 @@ public static void DeleteWithRetry(this IFileInfo file, int retryCount = 2, int /// Number of retry attempts tempts until the operation fails. /// Delay time in ms between each new attempt. /// Callback which gets always triggered if an attempt failed. - /// if the operation failed. otherwise. public static void DeleteWithRetry(this IFile _, string file, int retryCount = 2, int retryDelay = 500, Func? errorAction = null) { if (file == null) @@ -233,6 +231,61 @@ public static void DeleteWithRetry(this IFile _, string file, int retryCount = 2 }); } + /// + /// Tries to delete a file. + /// + /// The file to delete. + /// Number of retry attempts tempts until the operation fails. + /// Delay time in ms between each new attempt. + /// Callback which gets always triggered if an attempt failed. + /// if the file is successfully deleted; otherwise, . + public static bool TryDeleteWithRetry(this IFileInfo file, int retryCount = 2, int retryDelay = 500, Func? errorAction = null) + { + if (file == null) + throw new ArgumentNullException(nameof(file)); + + return file.FileSystem.File.TryDeleteWithRetry(file.FullName, retryCount, retryDelay, errorAction); + } + + /// + /// Tries to delete a file. + /// + /// + /// The file to delete. + /// Number of retry attempts tempts until the operation fails. + /// Delay time in ms between each new attempt. + /// Callback which gets always triggered if an attempt failed. + /// if the file is successfully deleted; otherwise, . + public static bool TryDeleteWithRetry(this IFile _, string file, int retryCount = 2, int retryDelay = 500, Func? errorAction = null) + { + if (file == null) + throw new ArgumentNullException(nameof(file)); + + if (!_.Exists(file)) + return true; + + return FileSystemUtilities.ExecuteFileSystemActionWithRetry(retryCount, retryDelay, () => _.Delete(file), false, + (ex, attempt) => + { + if (ex is UnauthorizedAccessException) + { + if (attempt == 0) + { + var attributes = _.GetAttributes(file); + if (attributes.HasFlag(FileAttributes.ReadOnly)) + { + _.SetAttributes(file, attributes & ~FileAttributes.ReadOnly); + errorAction?.Invoke(ex, attempt); + return true; + } + } + } + + errorAction?.Invoke(ex, attempt); + return false; + }); + } + /// /// Creates a temporary, hidden file which gets deleted once the returned stream is disposed. /// diff --git a/src/CommonUtilities.FileSystem/test/DirectoryCopierTest.cs b/src/CommonUtilities.FileSystem/test/DirectoryCopierTest.cs index 85c3d08..1d69c82 100644 --- a/src/CommonUtilities.FileSystem/test/DirectoryCopierTest.cs +++ b/src/CommonUtilities.FileSystem/test/DirectoryCopierTest.cs @@ -48,6 +48,7 @@ public void Test_CopyDirectory() .WithFile("test/1.txt").Which(f => f.HasStringContent("1")) .WithFile("test/2.txt").Which(f => f.HasStringContent("2")) .WithFile("test/3.txt").Which(f => f.HasStringContent("3")) + .WithFile("test/sub/4.txt").Which(f => f.HasStringContent("4")) .WithFile("other/3.txt").Which(f => f.HasStringContent("99")); var copier = new DirectoryCopier(_fileSystem); @@ -65,6 +66,7 @@ public void Test_CopyDirectory() Assert.Equal(1.0, progressValue); Assert.True(_fileSystem.File.Exists("other/1.txt")); + Assert.True(_fileSystem.File.Exists("other/sub/4.txt")); Assert.Equal("3", _fileSystem.File.ReadAllText("other/3.txt")); //fsStream.Dispose(); @@ -85,6 +87,7 @@ public async Task Test_CopyDirectoryAsync() .WithFile("test/1.txt").Which(f => f.HasStringContent("1")) .WithFile("test/2.txt").Which(f => f.HasStringContent("2")) .WithFile("test/3.txt").Which(f => f.HasStringContent("3")) + .WithFile("test/sub/4.txt").Which(f => f.HasStringContent("4")) .WithFile("other/3.txt").Which(f => f.HasStringContent("99")); var copier = new DirectoryCopier(_fileSystem); @@ -102,6 +105,7 @@ public async Task Test_CopyDirectoryAsync() Assert.Equal(1.0, progressValue); Assert.True(_fileSystem.File.Exists("other/1.txt")); + Assert.True(_fileSystem.File.Exists("other/sub/4.txt")); Assert.Equal("3", _fileSystem.File.ReadAllText("other/3.txt")); //fsStream.Dispose(); @@ -121,6 +125,7 @@ public void Test_MoveDirectory() .WithFile("test/1.txt").Which(f => f.HasStringContent("1")) .WithFile("test/2.txt").Which(f => f.HasStringContent("2")) .WithFile("test/3.txt").Which(f => f.HasStringContent("3")) + .WithFile("test/sub/4.txt").Which(f => f.HasStringContent("4")) .WithFile("other/3.txt").Which(f => f.HasStringContent("99")); var copier = new DirectoryCopier(_fileSystem); @@ -136,9 +141,10 @@ public void Test_MoveDirectory() Assert.True(delSuc); Assert.False(_fileSystem.Directory.Exists("test")); - var destinationFiles = _fileSystem.Directory.GetFiles("other"); - Assert.Equal(2, destinationFiles.Length); + var destinationFiles = _fileSystem.Directory.GetFiles("other", "*", SearchOption.AllDirectories); + Assert.Equal(3, destinationFiles.Length); Assert.True(_fileSystem.File.Exists("other/1.txt")); + Assert.True(_fileSystem.File.Exists("other/sub/4.txt")); Assert.Equal("3", _fileSystem.File.ReadAllText("other/3.txt")); return; @@ -156,6 +162,7 @@ public void Test_MoveDirectory_CannotDeleteSource() .WithFile("test/1.txt").Which(f => f.HasStringContent("1")) .WithFile("test/2.txt").Which(f => f.HasStringContent("2")) .WithFile("test/3.txt").Which(f => f.HasStringContent("3")) + .WithFile("test/sub/4.txt").Which(f => f.HasStringContent("4")) .WithFile("other/3.txt").Which(f => f.HasStringContent("99")); var copier = new DirectoryCopier(_fileSystem); @@ -175,6 +182,7 @@ public void Test_MoveDirectory_CannotDeleteSource() Assert.True(_fileSystem.File.Exists("other/1.txt")); Assert.True(_fileSystem.File.Exists("other/2.txt")); + Assert.True(_fileSystem.File.Exists("other/sub/4.txt")); Assert.Equal("3", _fileSystem.File.ReadAllText("other/3.txt")); fs.Dispose(); @@ -187,6 +195,7 @@ public async Task Test_MoveDirectoryAsync() .WithFile("test/1.txt").Which(f => f.HasStringContent("1")) .WithFile("test/2.txt").Which(f => f.HasStringContent("2")) .WithFile("test/3.txt").Which(f => f.HasStringContent("3")) + .WithFile("test/sub/4.txt").Which(f => f.HasStringContent("4")) .WithFile("other/3.txt").Which(f => f.HasStringContent("99")); var copier = new DirectoryCopier(_fileSystem); @@ -205,6 +214,7 @@ public async Task Test_MoveDirectoryAsync() Assert.True(_fileSystem.File.Exists("other/1.txt")); Assert.True(_fileSystem.File.Exists("other/2.txt")); + Assert.True(_fileSystem.File.Exists("other/sub/4.txt")); Assert.Equal("3", _fileSystem.File.ReadAllText("other/3.txt")); } diff --git a/src/CommonUtilities.FileSystem/test/DirectoryInfoExtensionsTest.cs b/src/CommonUtilities.FileSystem/test/DirectoryInfoExtensionsTest.cs index 1604b1b..ca520d6 100644 --- a/src/CommonUtilities.FileSystem/test/DirectoryInfoExtensionsTest.cs +++ b/src/CommonUtilities.FileSystem/test/DirectoryInfoExtensionsTest.cs @@ -98,7 +98,9 @@ public void Test_MoveToEx_CleanOverride() _fileSystem.Initialize() .WithFile("test/1.txt").Which(f => f.HasStringContent("1")) .WithFile("test/2.txt").Which(f => f.HasStringContent("2")) - .WithFile("other/3.txt").Which(f => f.HasStringContent("3")); + .WithFile("test/sub/5.txt").Which(f => f.HasStringContent("5")) + .WithFile("other/3.txt").Which(f => f.HasStringContent("3")) + .WithFile("other/sub/4.txt").Which(f => f.HasStringContent("4")); var dirToMove = _fileSystem.DirectoryInfo.New("test"); @@ -107,7 +109,10 @@ public void Test_MoveToEx_CleanOverride() Assert.True(delSuc); Assert.False(_fileSystem.Directory.Exists("test")); Assert.True(_fileSystem.Directory.Exists("other")); - Assert.Equal(2, _fileSystem.DirectoryInfo.New("other").GetFiles("*").Length); + Assert.Equal(3, _fileSystem.DirectoryInfo.New("other").GetFiles("*", SearchOption.AllDirectories).Length); + Assert.True(_fileSystem.File.Exists("other/1.txt")); + Assert.True(_fileSystem.File.Exists("other/2.txt")); + Assert.True(_fileSystem.File.Exists("other/sub/5.txt")); } [Fact] @@ -116,7 +121,10 @@ public void Test_MoveToEx_MergeOverride() _fileSystem.Initialize() .WithFile("test/1.txt").Which(f => f.HasStringContent("1")) .WithFile("test/2.txt").Which(f => f.HasStringContent("2")) - .WithFile("other/3.txt").Which(f => f.HasStringContent("3")); + .WithFile("test/sub1/4.txt").Which(f => f.HasStringContent("4")) + .WithFile("other/3.txt").Which(f => f.HasStringContent("3")) + .WithFile("other/2.txt").Which(f => f.HasStringContent("99")) + .WithFile("other/sub/5.txt").Which(f => f.HasStringContent("5")); var dirToMove = _fileSystem.DirectoryInfo.New("test"); @@ -125,7 +133,8 @@ public void Test_MoveToEx_MergeOverride() Assert.True(delSuc); Assert.False(_fileSystem.Directory.Exists("test")); Assert.True(_fileSystem.Directory.Exists("other")); - Assert.Equal(3, _fileSystem.DirectoryInfo.New("other").GetFiles("*").Length); + Assert.Equal(5, _fileSystem.DirectoryInfo.New("other").GetFiles("*", SearchOption.AllDirectories).Length); + Assert.Equal("2", _fileSystem.File.ReadAllText("other/2.txt")); } [PlatformSpecificFact(TestPlatformIdentifier.Windows)] @@ -139,7 +148,7 @@ public void Test_MoveToEx_MoveAcrossVolumes() var dirToMove = _fileSystem.DirectoryInfo.New("test"); dirToMove.MoveToEx("D:\\test", null, DirectoryOverwriteOption.NoOverwrite); - Assert.Equal(2, _fileSystem.DirectoryInfo.New("D:\\test").GetFiles("*").Length); + Assert.Equal(2, _fileSystem.DirectoryInfo.New("D:\\test").GetFiles("*", SearchOption.AllDirectories).Length); } [Fact] @@ -210,7 +219,9 @@ public async void Test_MoveToAsync_CleanOverride() _fileSystem.Initialize() .WithFile("test/1.txt").Which(f => f.HasStringContent("1")) .WithFile("test/2.txt").Which(f => f.HasStringContent("2")) - .WithFile("other/3.txt").Which(f => f.HasStringContent("3")); + .WithFile("test/sub/5.txt").Which(f => f.HasStringContent("5")) + .WithFile("other/3.txt").Which(f => f.HasStringContent("3")) + .WithFile("other/sub/4.txt").Which(f => f.HasStringContent("4")); var dirToMove = _fileSystem.DirectoryInfo.New("test"); @@ -219,7 +230,10 @@ public async void Test_MoveToAsync_CleanOverride() Assert.True(delSuc); Assert.False(_fileSystem.Directory.Exists("test")); Assert.True(_fileSystem.Directory.Exists("other")); - Assert.Equal(2, _fileSystem.DirectoryInfo.New("other").GetFiles("*").Length); + Assert.Equal(3, _fileSystem.DirectoryInfo.New("other").GetFiles("*", SearchOption.AllDirectories).Length); + Assert.True(_fileSystem.File.Exists("other/1.txt")); + Assert.True(_fileSystem.File.Exists("other/2.txt")); + Assert.True(_fileSystem.File.Exists("other/sub/5.txt")); } [Fact] @@ -228,7 +242,10 @@ public async void Test_MoveToAsync_MergeOverride() _fileSystem.Initialize() .WithFile("test/1.txt").Which(f => f.HasStringContent("1")) .WithFile("test/2.txt").Which(f => f.HasStringContent("2")) - .WithFile("other/3.txt").Which(f => f.HasStringContent("3")); + .WithFile("test/sub1/4.txt").Which(f => f.HasStringContent("4")) + .WithFile("other/3.txt").Which(f => f.HasStringContent("3")) + .WithFile("other/2.txt").Which(f => f.HasStringContent("99")) + .WithFile("other/sub/5.txt").Which(f => f.HasStringContent("5")); var dirToMove = _fileSystem.DirectoryInfo.New("test"); @@ -237,7 +254,8 @@ public async void Test_MoveToAsync_MergeOverride() Assert.True(delSuc); Assert.False(_fileSystem.Directory.Exists("test")); Assert.True(_fileSystem.Directory.Exists("other")); - Assert.Equal(3, _fileSystem.DirectoryInfo.New("other").GetFiles("*").Length); + Assert.Equal(5, _fileSystem.DirectoryInfo.New("other").GetFiles("*", SearchOption.AllDirectories).Length); + Assert.Equal("2", _fileSystem.File.ReadAllText("other/2.txt")); } [PlatformSpecificFact(TestPlatformIdentifier.Windows)] @@ -251,7 +269,7 @@ public async void Test_MoveToAsync_MoveAcrossVolumes() var dirToMove = _fileSystem.DirectoryInfo.New("test"); await dirToMove.MoveToAsync("D:\\test", null, DirectoryOverwriteOption.NoOverwrite); - Assert.Equal(2, _fileSystem.DirectoryInfo.New("D:\\test").GetFiles("*").Length); + Assert.Equal(2, _fileSystem.DirectoryInfo.New("D:\\test").GetFiles("*", SearchOption.AllDirectories).Length); } [Fact] @@ -319,14 +337,19 @@ public void Test_Copy_CleanOverwrite() _fileSystem.Initialize() .WithFile("test/1.txt").Which(f => f.HasStringContent("1")) .WithFile("test/2.txt").Which(f => f.HasStringContent("2")) - .WithFile("other/3.txt").Which(f => f.HasStringContent("3")); + .WithFile("test/sub/5.txt").Which(f => f.HasStringContent("5")) + .WithFile("other/3.txt").Which(f => f.HasStringContent("3")) + .WithFile("other/sub/4.txt").Which(f => f.HasStringContent("4")); var dirToCopy = _fileSystem.DirectoryInfo.New("test"); dirToCopy.Copy("other", null, DirectoryOverwriteOption.CleanOverwrite); Assert.True(_fileSystem.Directory.Exists("test")); Assert.True(_fileSystem.Directory.Exists("other")); - Assert.Equal(2, _fileSystem.DirectoryInfo.New("other").GetFiles("*").Length); + Assert.Equal(3, _fileSystem.DirectoryInfo.New("other").GetFiles("*", SearchOption.AllDirectories).Length); + Assert.True(_fileSystem.File.Exists("other/1.txt")); + Assert.True(_fileSystem.File.Exists("other/2.txt")); + Assert.True(_fileSystem.File.Exists("other/sub/5.txt")); } [Fact] @@ -335,14 +358,18 @@ public void Test_Copy_MergeOverwrite() _fileSystem.Initialize() .WithFile("test/1.txt").Which(f => f.HasStringContent("1")) .WithFile("test/2.txt").Which(f => f.HasStringContent("2")) - .WithFile("other/3.txt").Which(f => f.HasStringContent("3")); + .WithFile("test/sub1/4.txt").Which(f => f.HasStringContent("4")) + .WithFile("other/3.txt").Which(f => f.HasStringContent("3")) + .WithFile("other/2.txt").Which(f => f.HasStringContent("99")) + .WithFile("other/sub/5.txt").Which(f => f.HasStringContent("5")); var dirToCopy = _fileSystem.DirectoryInfo.New("test"); dirToCopy.Copy("other", null, DirectoryOverwriteOption.MergeOverwrite); Assert.True(_fileSystem.Directory.Exists("test")); Assert.True(_fileSystem.Directory.Exists("other")); - Assert.Equal(3, _fileSystem.DirectoryInfo.New("other").GetFiles("*").Length); + Assert.Equal(5, _fileSystem.DirectoryInfo.New("other").GetFiles("*", SearchOption.AllDirectories).Length); + Assert.Equal("2", _fileSystem.File.ReadAllText("other/2.txt")); } @@ -359,7 +386,7 @@ public void Test_Copy_AcrossDrives() dirToCopy.Copy("D:\\other", null, DirectoryOverwriteOption.CleanOverwrite); Assert.True(_fileSystem.Directory.Exists("test")); Assert.True(_fileSystem.Directory.Exists("D:\\other")); - Assert.Equal(2, _fileSystem.DirectoryInfo.New("D:\\other").GetFiles("*").Length); + Assert.Equal(2, _fileSystem.DirectoryInfo.New("D:\\other").GetFiles("*", SearchOption.AllDirectories).Length); } [Fact] @@ -388,14 +415,19 @@ public async void Test_CopyAsync_CleanOverwrite() _fileSystem.Initialize() .WithFile("test/1.txt").Which(f => f.HasStringContent("1")) .WithFile("test/2.txt").Which(f => f.HasStringContent("2")) - .WithFile("other/3.txt").Which(f => f.HasStringContent("3")); + .WithFile("test/sub/5.txt").Which(f => f.HasStringContent("5")) + .WithFile("other/3.txt").Which(f => f.HasStringContent("3")) + .WithFile("other/sub/4.txt").Which(f => f.HasStringContent("4")); var dirToCopy = _fileSystem.DirectoryInfo.New("test"); await dirToCopy.CopyAsync("other", null, DirectoryOverwriteOption.CleanOverwrite); Assert.True(_fileSystem.Directory.Exists("test")); Assert.True(_fileSystem.Directory.Exists("other")); - Assert.Equal(2, _fileSystem.DirectoryInfo.New("other").GetFiles("*").Length); + Assert.Equal(3, _fileSystem.DirectoryInfo.New("other").GetFiles("*", SearchOption.AllDirectories).Length); + Assert.True(_fileSystem.File.Exists("other/1.txt")); + Assert.True(_fileSystem.File.Exists("other/2.txt")); + Assert.True(_fileSystem.File.Exists("other/sub/5.txt")); } [Fact] @@ -404,14 +436,18 @@ public async void Test_CopyAsync_MergeOverwrite() _fileSystem.Initialize() .WithFile("test/1.txt").Which(f => f.HasStringContent("1")) .WithFile("test/2.txt").Which(f => f.HasStringContent("2")) - .WithFile("other/3.txt").Which(f => f.HasStringContent("3")); + .WithFile("test/sub1/4.txt").Which(f => f.HasStringContent("4")) + .WithFile("other/3.txt").Which(f => f.HasStringContent("3")) + .WithFile("other/2.txt").Which(f => f.HasStringContent("99")) + .WithFile("other/sub/5.txt").Which(f => f.HasStringContent("5")); var dirToCopy = _fileSystem.DirectoryInfo.New("test"); await dirToCopy.CopyAsync("other", null, DirectoryOverwriteOption.MergeOverwrite); Assert.True(_fileSystem.Directory.Exists("test")); Assert.True(_fileSystem.Directory.Exists("other")); - Assert.Equal(3, _fileSystem.DirectoryInfo.New("other").GetFiles("*").Length); + Assert.Equal(5, _fileSystem.DirectoryInfo.New("other").GetFiles("*", SearchOption.AllDirectories).Length); + Assert.Equal("2", _fileSystem.File.ReadAllText("other/2.txt")); } @@ -428,7 +464,7 @@ public async void Test_CopyAsync_AcrossDrives() await dirToCopy.CopyAsync("D:\\other", null, DirectoryOverwriteOption.CleanOverwrite); Assert.True(_fileSystem.Directory.Exists("test")); Assert.True(_fileSystem.Directory.Exists("D:\\other")); - Assert.Equal(2, _fileSystem.DirectoryInfo.New("D:\\other").GetFiles("*").Length); + Assert.Equal(2, _fileSystem.DirectoryInfo.New("D:\\other").GetFiles("*", SearchOption.AllDirectories).Length); } diff --git a/src/CommonUtilities.FileSystem/test/FileInfoExtensionsTest.cs b/src/CommonUtilities.FileSystem/test/FileInfoExtensionsTest.cs index f7f1ec7..4a0dd83 100644 --- a/src/CommonUtilities.FileSystem/test/FileInfoExtensionsTest.cs +++ b/src/CommonUtilities.FileSystem/test/FileInfoExtensionsTest.cs @@ -52,11 +52,60 @@ public void Test_DeleteWithRetry() var file2 = _fileSystem.FileInfo.New("text2.txt"); file2.Attributes |= FileAttributes.ReadOnly; + var fs1 = _fileSystem.FileStream.New(file1.FullName, FileMode.Open, FileAccess.Read, FileShare.None); + var fs2 = _fileSystem.FileStream.New(file2.FullName, FileMode.Open, FileAccess.Read, FileShare.None); + Assert.Throws(() => file1.DeleteWithRetry()); + Assert.Throws(() => _fileSystem.File.DeleteWithRetry(file2.FullName)); + + file1.Refresh(); + file2.Refresh(); + Assert.True(file1.Exists); + Assert.True(file2.Exists); + + fs1.Dispose(); + fs2.Dispose(); + file1.Refresh(); file2.Refresh(); file1.DeleteWithRetry(); - file2.DeleteWithRetry(); - + _fileSystem.File.TryDeleteWithRetry(file2.FullName); + + + file1.Refresh(); + file2.Refresh(); + Assert.False(file1.Exists); + Assert.False(file2.Exists); + } + + [Fact] + public void Test_TryDeleteWithRetry() + { + _fileSystem.Initialize() + .WithFile("text1.txt") + .WithFile("text2.txt"); + + var file1 = _fileSystem.FileInfo.New("text1.txt"); + var file2 = _fileSystem.FileInfo.New("text2.txt"); + file2.Attributes |= FileAttributes.ReadOnly; + + var fs1 = _fileSystem.FileStream.New(file1.FullName, FileMode.Open, FileAccess.Read, FileShare.None); + var fs2 = _fileSystem.FileStream.New(file2.FullName, FileMode.Open, FileAccess.Read, FileShare.None); + Assert.False(file1.TryDeleteWithRetry()); + Assert.False(_fileSystem.File.TryDeleteWithRetry(file2.FullName)); + + file1.Refresh(); + file2.Refresh(); + Assert.True(file1.Exists); + Assert.True(file2.Exists); + + fs1.Dispose(); + fs2.Dispose(); + + file1.Refresh(); + file2.Refresh(); + Assert.True(file1.TryDeleteWithRetry()); + Assert.True(_fileSystem.File.TryDeleteWithRetry(file2.FullName)); + file1.Refresh(); file2.Refresh(); Assert.False(file1.Exists); diff --git a/version.json b/version.json index 1193528..ad503a5 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "11.0", + "version": "11.1", "assemblyVersion": { "precision": "major" },