Skip to content
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
2 changes: 2 additions & 0 deletions src/Centeva.ObjectStorage/Builtin/DiskObjectStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public Task RenameAsync(StoragePath sourcePath, StoragePath destinationPath, Can

if (File.Exists(filePath))
{
if (File.Exists(newFilePath))
File.Delete(newFilePath);
File.Move(filePath, newFilePath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,39 @@ public async Task RenameAsync_RenamesObject()
content.ShouldBe(_testFileContent);
}

[Fact]
public async Task RenameAsync_WithExistingDestination_OverwritesDestination()
{
// Arrange
var originalPath = await WriteToRandomPathAsync();
var destinationPath = RandomStoragePath();

// Create a copy at the destination path first
var differentContent = "Different content that should be overwritten.";
await _sut.WriteAsync(destinationPath, new MemoryStream(Encoding.UTF8.GetBytes(differentContent)));

// Verify both files exist before rename
(await _sut.ExistsAsync(originalPath)).ShouldBeTrue();
(await _sut.ExistsAsync(destinationPath)).ShouldBeTrue();

// Act
await _sut.RenameAsync(originalPath, destinationPath);

// Assert
// Check that the original object no longer exists
(await _sut.ExistsAsync(originalPath)).ShouldBeFalse();

// Check that the destination object still exists
(await _sut.ExistsAsync(destinationPath)).ShouldBeTrue();

// Check that the destination content matches the original content
using var stream = await _sut.OpenReadAsync(destinationPath);
stream.ShouldNotBeNull();
using var reader = new StreamReader(stream!);
var content = await reader.ReadToEndAsync();
content.ShouldBe(_testFileContent);
}

[Fact]
public async Task GetAsync_RetrievesStorageEntry()
{
Expand Down