Skip to content

Commit

Permalink
Merge pull request #95 from GerardSmit/fix/mount-filesystem-crosscopy
Browse files Browse the repository at this point in the history
Fix cross-filesystem operations in MountFileSystem
  • Loading branch information
xoofx authored Jul 13, 2024
2 parents ec3a3e5 + 7e7f667 commit 083b29d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Zio.Tests/FileSystems/TestMemoryFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ public void TestMoveFileCross()
Assert.Equal(TriggerMemoryFileSystem.TriggerType.Move, fs.Triggered);
}

[Fact]
public void TestMoveFileCrossMount()
{
var fs = new TriggerMemoryFileSystem();
fs.CreateDirectory("/sub1");
fs.CreateDirectory("/sub2");
var mount = new MountFileSystem();
var sub1 = new SubFileSystem(fs, "/sub1");
var sub2 = new SubFileSystem(fs, "/sub2");
mount.Mount("/sub2-mount", sub2);
sub1.WriteAllText("/file.txt", "test");
sub1.MoveFileCross("/file.txt", mount, "/sub2-mount/file.txt");
Assert.Equal("test", sub2.ReadAllText("/file.txt"));
Assert.False(sub1.FileExists("/file.txt"));
Assert.Equal(TriggerMemoryFileSystem.TriggerType.Move, fs.Triggered);
}

private sealed class TriggerMemoryFileSystem : MemoryFileSystem
{
public enum TriggerType
Expand Down
2 changes: 1 addition & 1 deletion src/Zio/FileSystems/ComposeFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,5 @@ protected override UPath ConvertPathFromInternalImpl(string innerPath)
protected abstract UPath ConvertPathFromDelegate(UPath path);

protected override (IFileSystem FileSystem, UPath Path) ResolvePathImpl(UPath path)
=> FallbackSafe.ResolvePath(ConvertPathToDelegate(path));
=> Fallback?.ResolvePath(ConvertPathToDelegate(path)) ?? base.ResolvePathImpl(path);
}
13 changes: 13 additions & 0 deletions src/Zio/FileSystems/MountFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,19 @@ protected override bool TryResolveLinkTargetImpl(UPath linkPath, out UPath resol
return true;
}

/// <inheritdoc />
protected override (IFileSystem FileSystem, UPath Path) ResolvePathImpl(UPath path)
{
var mountfs = TryGetMountOrNext(ref path);

if (mountfs is null)
{
return base.ResolvePathImpl(path);
}

return mountfs.ResolvePath(path);
}

/// <inheritdoc />
protected override IEnumerable<UPath> EnumeratePathsImpl(UPath path, string searchPattern, SearchOption searchOption, SearchTarget searchTarget)
{
Expand Down

0 comments on commit 083b29d

Please sign in to comment.