Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #309 - FolderFileStorage doesn't overwrite existing content #310

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/Foundatio.TestHarness/Storage/FileStorageTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,28 @@ public virtual void CanUseDataDirectory()
Assert.NotEqual(DATA_DIRECTORY_QUEUE_FOLDER, storage.Folder);
Assert.True(storage.Folder.EndsWith("Queue" + Path.DirectorySeparatorChar), storage.Folder);
}

public virtual async Task CanSaveOverExistingStoredContent()
{
using var storage = GetStorage();
if (storage == null)
return;

await ResetAsync(storage);

var shortIdInfo = new PostInfo { ProjectId = "123" };
var longIdInfo = new PostInfo { ProjectId = "1234567890" };

string path = "test.json";
await storage.SaveObjectAsync(path, longIdInfo);
await storage.SaveObjectAsync(path, shortIdInfo);

var actualInfo = await storage.GetObjectAsync<PostInfo>(path);
Assert.Equal(shortIdInfo, actualInfo);
}
}

public class PostInfo
public record PostInfo
{
public int ApiVersion { get; set; }
public string CharSet { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Foundatio/Storage/FolderFileStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Task<Stream> GetFileStreamAsync(string path, StreamMode streamMode, Cance
string fullPath = Path.Combine(Folder, normalizedPath);
EnsureDirectory(fullPath);

var stream = streamMode == StreamMode.Read ? File.OpenRead(fullPath) : File.OpenWrite(fullPath);
var stream = streamMode == StreamMode.Read ? File.OpenRead(fullPath) : new FileStream(fullPath, FileMode.Create, FileAccess.Write);
return Task.FromResult<Stream>(stream);
}

Expand Down
6 changes: 6 additions & 0 deletions tests/Foundatio.Tests/Storage/FolderFileStorageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ public override Task WillWriteStreamContentAsync()
return base.WillWriteStreamContentAsync();
}

[Fact]
public override Task CanSaveOverExistingStoredContent()
{
return base.CanSaveOverExistingStoredContent();
}

[Fact]
public async Task WillNotReturnDirectoryInGetPagedFileListAsync()
{
Expand Down
6 changes: 6 additions & 0 deletions tests/Foundatio.Tests/Storage/InMemoryFileStorageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,10 @@ public override Task WillWriteStreamContentAsync()
{
return base.WillWriteStreamContentAsync();
}

[Fact]
public override Task CanSaveOverExistingStoredContent()
{
return base.CanSaveOverExistingStoredContent();
}
}
6 changes: 6 additions & 0 deletions tests/Foundatio.Tests/Storage/ScopedFolderFileStorageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ public override Task WillWriteStreamContentAsync()
return base.WillWriteStreamContentAsync();
}

[Fact]
public override Task CanSaveOverExistingStoredContent()
{
return base.CanSaveOverExistingStoredContent();
}

[Fact]
public async Task WillNotReturnDirectoryInGetPagedFileListAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,10 @@ public override Task WillWriteStreamContentAsync()
{
return base.WillWriteStreamContentAsync();
}

[Fact]
public override Task CanSaveOverExistingStoredContent()
{
return base.CanSaveOverExistingStoredContent();
}
}