Skip to content

Commit

Permalink
Fix staging secondaryFiles and listing
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-tan committed May 31, 2022
1 parent 61bcf52 commit 78fa776
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 60 deletions.
39 changes: 39 additions & 0 deletions source/shaft/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,42 @@ void enforceValid(Directory dir) @safe
_ => true
);
}

///
Node collectListing(string baseDir)
in(baseDir.isDir)
in(baseDir.isAbsolute)
out(r; r.type == NodeType.sequence || r.type == NodeType.null_)
{
import std.file : dirEntries, SpanMode;

auto ret = Node((Node[]).init);
foreach(string name; dirEntries(baseDir, SpanMode.shallow, false))
{
assert(name.isAbsolute);
if (name.isFile)
{
ret.add(Node(name.toStagedFile));
}
else if (name.isDir)
{
import dyaml : YAMLNull;
auto listing = collectListing(name);
ret.add(Node(name.toStagedDirectory(Node(YAMLNull()), listing)));
}
else
{
assert(false);
}
}

if (ret.sequence.empty)
{
import dyaml : YAMLNull;
return Node(YAMLNull());
}
else
{
return ret;
}
}
Loading

0 comments on commit 78fa776

Please sign in to comment.