-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompositeDirectory.cs
More file actions
58 lines (46 loc) · 2.11 KB
/
CompositeDirectory.cs
File metadata and controls
58 lines (46 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Runtime.CompilerServices;
using Ramstack.FileSystem.Null;
namespace Ramstack.FileSystem.Composite;
/// <summary>
/// Represents a <see cref="VirtualDirectory"/> implementation for the <see cref="CompositeFileSystem"/> class.
/// </summary>
internal sealed class CompositeDirectory : VirtualDirectory
{
private readonly CompositeFileSystem _fs;
/// <inheritdoc />
public override IVirtualFileSystem FileSystem => _fs;
/// <summary>
/// Initializes a new instance of the <see cref="CompositeDirectory"/> class.
/// </summary>
/// <param name="fileSystem">The file system associated with this file.</param>
/// <param name="path">The path of the directory.</param>
public CompositeDirectory(CompositeFileSystem fileSystem, string path) : base(path) =>
_fs = fileSystem;
/// <inheritdoc />
protected override ValueTask<VirtualNodeProperties?> GetPropertiesCoreAsync(CancellationToken cancellationToken) =>
new ValueTask<VirtualNodeProperties?>(VirtualNodeProperties.None);
/// <inheritdoc />
protected override ValueTask CreateCoreAsync(CancellationToken cancellationToken) =>
default;
/// <inheritdoc />
protected override ValueTask DeleteCoreAsync(CancellationToken cancellationToken) =>
default;
/// <inheritdoc />
protected override async IAsyncEnumerable<VirtualNode> GetFileNodesCoreAsync([EnumeratorCancellation] CancellationToken cancellationToken)
{
var set = new HashSet<string>();
foreach (var fs in _fs.InternalFileSystems)
{
await foreach (var node in fs.GetFileNodesAsync(FullName, cancellationToken).ConfigureAwait(false))
{
if (node is NotFoundFile or NotFoundDirectory)
continue;
if (!set.Add(node.FullName))
continue;
yield return node is VirtualFile file
? new CompositeFile(_fs, node.FullName, file)
: new CompositeDirectory(_fs, node.FullName);
}
}
}
}