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

Fix cross-filesystem operations in MountFileSystem #95

Merged
merged 2 commits into from
Jul 13, 2024
Merged
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
17 changes: 17 additions & 0 deletions src/Zio.Tests/FileSystems/TestMemoryFileSystem.cs
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/Zio/FileSystems/ComposeFileSystem.cs
Original file line number Diff line number Diff line change
@@ -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
@@ -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)
{