Skip to content

Commit 083b29d

Browse files
authored
Merge pull request #95 from GerardSmit/fix/mount-filesystem-crosscopy
Fix cross-filesystem operations in MountFileSystem
2 parents ec3a3e5 + 7e7f667 commit 083b29d

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/Zio.Tests/FileSystems/TestMemoryFileSystem.cs

+17
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,23 @@ public void TestMoveFileCross()
9393
Assert.Equal(TriggerMemoryFileSystem.TriggerType.Move, fs.Triggered);
9494
}
9595

96+
[Fact]
97+
public void TestMoveFileCrossMount()
98+
{
99+
var fs = new TriggerMemoryFileSystem();
100+
fs.CreateDirectory("/sub1");
101+
fs.CreateDirectory("/sub2");
102+
var mount = new MountFileSystem();
103+
var sub1 = new SubFileSystem(fs, "/sub1");
104+
var sub2 = new SubFileSystem(fs, "/sub2");
105+
mount.Mount("/sub2-mount", sub2);
106+
sub1.WriteAllText("/file.txt", "test");
107+
sub1.MoveFileCross("/file.txt", mount, "/sub2-mount/file.txt");
108+
Assert.Equal("test", sub2.ReadAllText("/file.txt"));
109+
Assert.False(sub1.FileExists("/file.txt"));
110+
Assert.Equal(TriggerMemoryFileSystem.TriggerType.Move, fs.Triggered);
111+
}
112+
96113
private sealed class TriggerMemoryFileSystem : MemoryFileSystem
97114
{
98115
public enum TriggerType

src/Zio/FileSystems/ComposeFileSystem.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,5 +276,5 @@ protected override UPath ConvertPathFromInternalImpl(string innerPath)
276276
protected abstract UPath ConvertPathFromDelegate(UPath path);
277277

278278
protected override (IFileSystem FileSystem, UPath Path) ResolvePathImpl(UPath path)
279-
=> FallbackSafe.ResolvePath(ConvertPathToDelegate(path));
279+
=> Fallback?.ResolvePath(ConvertPathToDelegate(path)) ?? base.ResolvePathImpl(path);
280280
}

src/Zio/FileSystems/MountFileSystem.cs

+13
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,19 @@ protected override bool TryResolveLinkTargetImpl(UPath linkPath, out UPath resol
593593
return true;
594594
}
595595

596+
/// <inheritdoc />
597+
protected override (IFileSystem FileSystem, UPath Path) ResolvePathImpl(UPath path)
598+
{
599+
var mountfs = TryGetMountOrNext(ref path);
600+
601+
if (mountfs is null)
602+
{
603+
return base.ResolvePathImpl(path);
604+
}
605+
606+
return mountfs.ResolvePath(path);
607+
}
608+
596609
/// <inheritdoc />
597610
protected override IEnumerable<UPath> EnumeratePathsImpl(UPath path, string searchPattern, SearchOption searchOption, SearchTarget searchTarget)
598611
{

0 commit comments

Comments
 (0)