Skip to content
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
58 changes: 58 additions & 0 deletions src/Zio/FileSystems/MountFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,64 @@ public IFileSystem Unmount(UPath name)
return mountFileSystem;
}

/// <summary>
/// Attempts to find information about the mount that a given path maps to.
/// </summary>
/// <param name="path">The path to search for.</param>
/// <param name="name">The mount name that the <paramref name="path"/> belongs to.</param>
/// <param name="fileSystem">The mounted filesystem that the <paramref name="path"/> is located in.</param>
/// <param name="fileSystemPath">The path inside of <paramref name="fileSystem"/> that refers to the file at <paramref name="path"/>.</param>
/// <returns>True if the <paramref name="path"/> was found in a mounted filesystem.</returns>
/// <exception cref="System.ArgumentNullException">The <paramref name="path"/> must not be null.</exception>
/// <exception cref="System.ArgumentException">The <paramref name="path"/> must be absolute.</exception>
public bool TryGetMount(UPath path, out UPath name, out IFileSystem fileSystem, out UPath fileSystemPath)
{
path.AssertNotNull();
path.AssertAbsolute();

var fs = TryGetMountOrNext(ref path, out name);

if (fs == null || name.IsNull)
{
name = null;
fileSystem = null;
fileSystemPath = null;
return false;
}

fileSystem = fs;
fileSystemPath = path;
return true;
}

/// <summary>
/// Attempts to find the mount name that a filesystem has been mounted to
/// </summary>
/// <param name="fileSystem">The mounted filesystem to search for.</param>
/// <param name="name">The mount name that the <paramref name="fileSystem"/> is mounted with.</param>
/// <returns>True if the <paramref name="fileSystem"/> is mounted.</returns>
/// <exception cref="System.ArgumentNullException">The <paramref name="fileSystem"/> must not be null.</exception>
public bool TryGetMountName(IFileSystem fileSystem, out UPath name)
{
if (fileSystem == null)
throw new ArgumentNullException(nameof(fileSystem));

lock (_mounts)
{
foreach (var mount in _mounts)
{
if (mount.Value != fileSystem)
continue;

name = mount.Key;
return true;
}
}

name = null;
return false;
}

/// <inheritdoc />
protected override void CreateDirectoryImpl(UPath path)
{
Expand Down