-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompositeDirectory.cs
More file actions
92 lines (75 loc) · 3.37 KB
/
CompositeDirectory.cs
File metadata and controls
92 lines (75 loc) · 3.37 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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))
yield return node is VirtualFile file
? new CompositeFile(_fs, node.FullName, file)
: new CompositeDirectory(_fs, node.FullName);
}
}
}
/// <inheritdoc />
protected override async IAsyncEnumerable<VirtualFile> GetFilesCoreAsync([EnumeratorCancellation] CancellationToken cancellationToken)
{
var set = new HashSet<string>();
foreach (var fs in _fs.InternalFileSystems)
{
await foreach (var file in fs.GetFilesAsync(FullName, cancellationToken).ConfigureAwait(false))
{
if (file is NotFoundFile)
continue;
if (set.Add(file.FullName))
yield return new CompositeFile(_fs, file.FullName, file);
}
}
}
/// <inheritdoc />
protected override async IAsyncEnumerable<VirtualDirectory> GetDirectoriesCoreAsync([EnumeratorCancellation] CancellationToken cancellationToken)
{
var set = new HashSet<string>();
foreach (var fs in _fs.InternalFileSystems)
{
await foreach (var directory in fs.GetDirectoriesAsync(FullName, cancellationToken).ConfigureAwait(false))
{
if (directory is NotFoundDirectory)
continue;
if (set.Add(directory.FullName))
yield return new CompositeDirectory(_fs, directory.FullName);
}
}
}
}