Skip to content

Commit

Permalink
fix(mockfs): Correctly handle mkdir with absolute path
Browse files Browse the repository at this point in the history
This worked so far because CWD is always root in unittests.
  • Loading branch information
Geod24 committed Sep 24, 2024
1 parent 62d314d commit 77b51a1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions source/dub/internal/io/mockfs.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ public final class MockFS : Filesystem {
///
private FSEntry cwd;

///
private FSEntry root;

///
public this () scope
{
this.cwd = new FSEntry();
this.root = this.cwd = new FSEntry();
}

public override NativePath getcwd () const scope
Expand All @@ -41,7 +44,10 @@ public final class MockFS : Filesystem {
/// Ditto
public override void mkdir (in NativePath path) scope
{
this.cwd.mkdir(path);
if (path.absolute())
this.root.mkdir(path);
else
this.cwd.mkdir(path);
}

/// Ditto
Expand Down Expand Up @@ -421,9 +427,10 @@ public class FSEntry
/// Implements `mkdir -p`, returns the created directory
public FSEntry mkdir (in NativePath path) scope
{
auto relp = this.relativePath(path);
assert(!path.absolute() || this.parent is null,
`FSEntry.mkdir needs to be called with a relative path`);
// Check if the child already exists
auto segments = relp.bySegment;
auto segments = path.bySegment;
auto child = this.lookup(segments.front.name);
if (child is null) {
child = new FSEntry(this, Type.Directory, segments.front.name);
Expand Down

0 comments on commit 77b51a1

Please sign in to comment.