diff --git a/src/Foundatio.TestHarness/Storage/FileStorageTestsBase.cs b/src/Foundatio.TestHarness/Storage/FileStorageTestsBase.cs index 2c21898f..31cc6edf 100644 --- a/src/Foundatio.TestHarness/Storage/FileStorageTestsBase.cs +++ b/src/Foundatio.TestHarness/Storage/FileStorageTestsBase.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Concurrent; using System.IO; using System.Linq; @@ -402,6 +402,10 @@ public virtual async Task CanDeleteNestedFolderAsync() Assert.True(await storage.ExistsAsync(@"x\hello.txt")); Assert.False(await storage.ExistsAsync(@"x\nested\hello.txt")); Assert.False(await storage.ExistsAsync(@"x\nested\world.csv")); + + Assert.Equal(1, await storage.DeleteFilesAsync(@"x\hello*")); + Assert.Empty(await storage.GetFileListAsync()); + Assert.False(await storage.ExistsAsync(@"x\hello.txt")); } } diff --git a/src/Foundatio/Storage/InMemoryFileStorage.cs b/src/Foundatio/Storage/InMemoryFileStorage.cs index cf66a64c..6f18e0c8 100644 --- a/src/Foundatio/Storage/InMemoryFileStorage.cs +++ b/src/Foundatio/Storage/InMemoryFileStorage.cs @@ -228,11 +228,10 @@ public Task DeleteFilesAsync(string searchPattern = null, CancellationToken if (searchPattern[searchPattern.Length - 1] == Path.DirectorySeparatorChar) searchPattern = $"{searchPattern}*"; - else if (!searchPattern.EndsWith(Path.DirectorySeparatorChar + "*") && !Path.HasExtension(searchPattern)) + else if (!searchPattern.EndsWith("*") && !Path.HasExtension(searchPattern)) searchPattern = Path.Combine(searchPattern, "*"); var regex = new Regex($"^{Regex.Escape(searchPattern).Replace("\\*", ".*?")}$"); - var keys = _storage.Keys.Where(k => regex.IsMatch(k)).Select(k => _storage[k].Spec).ToList(); _logger.LogInformation("Deleting {FileCount} files matching {SearchPattern} (Regex={SearchPatternRegex})", keys.Count, searchPattern, regex);