Skip to content

Commit

Permalink
Fixed a bug where folder file storage wasn't returning deleted counts.
Browse files Browse the repository at this point in the history
  • Loading branch information
niemyjski committed Sep 25, 2024
1 parent f161567 commit 8a7d6a4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Foundatio.TestHarness/Storage/FileStorageTestsBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -396,7 +396,7 @@ public virtual async Task CanDeleteNestedFolderAsync()
Assert.Equal(2, (await storage.GetFileListAsync(@"x\nested\*")).Count);
Assert.Equal(2, (await storage.GetFileListAsync(@"x\*.txt")).Count);

await storage.DeleteFilesAsync(@"x\nested\*");
Assert.Equal(2, await storage.DeleteFilesAsync(@"x\nested\*"));

Assert.Single(await storage.GetFileListAsync());
Assert.True(await storage.ExistsAsync(@"x\hello.txt"));
Expand Down
8 changes: 4 additions & 4 deletions src/Foundatio/Storage/FolderFileStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public Task<int> DeleteFilesAsync(string searchPattern = null, CancellationToken
if (Directory.Exists(Folder))
{
_logger.LogInformation("Deleting {Directory} directory", Folder);
count += Directory.EnumerateFiles(Folder, "*,*", SearchOption.AllDirectories).Count();
count += Directory.EnumerateFiles(Folder, "*.*", SearchOption.AllDirectories).Count();
Directory.Delete(Folder, true);
_logger.LogTrace("Finished deleting {Directory} directory with {FileCount} files", Folder, count);
}
Expand All @@ -249,13 +249,13 @@ public Task<int> DeleteFilesAsync(string searchPattern = null, CancellationToken

searchPattern = searchPattern.NormalizePath();
string path = Path.Combine(Folder, searchPattern);
if (path[path.Length - 1] == Path.DirectorySeparatorChar || path.EndsWith(Path.DirectorySeparatorChar + "*"))
if (path[path.Length - 1] == Path.DirectorySeparatorChar || path.EndsWith($"{Path.DirectorySeparatorChar}*"))
{
string directory = Path.GetDirectoryName(path);
if (Directory.Exists(directory))
{
_logger.LogInformation("Deleting {Directory} directory", directory);
count += Directory.EnumerateFiles(directory, "*,*", SearchOption.AllDirectories).Count();
count += Directory.EnumerateFiles(directory, "*.*", SearchOption.AllDirectories).Count();
Directory.Delete(directory, true);
_logger.LogTrace("Finished deleting {Directory} directory with {FileCount} files", directory, count);
return Task.FromResult(count);
Expand All @@ -267,7 +267,7 @@ public Task<int> DeleteFilesAsync(string searchPattern = null, CancellationToken
if (Directory.Exists(path))
{
_logger.LogInformation("Deleting {Directory} directory", path);
count += Directory.EnumerateFiles(path, "*,*", SearchOption.AllDirectories).Count();
count += Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories).Count();
Directory.Delete(path, true);
_logger.LogTrace("Finished deleting {Directory} directory with {FileCount} files", path, count);
return Task.FromResult(count);
Expand Down

0 comments on commit 8a7d6a4

Please sign in to comment.