diff --git a/source/dub/internal/vibecompat/inet/path.d b/source/dub/internal/vibecompat/inet/path.d index e2b352b..7277e76 100644 --- a/source/dub/internal/vibecompat/inet/path.d +++ b/source/dub/internal/vibecompat/inet/path.d @@ -185,6 +185,8 @@ /// The parent path @property NativePath parentPath() const { return this[0 .. length-1]; } + /// Forward compatibility with vibe-d + @property bool hasParentPath() const { return length > 1; } /// The list of path entries of which this path is composed @property immutable(PathEntry)[] nodes() const { return m_nodes; } diff --git a/source/dub/test/base.d b/source/dub/test/base.d index ddd0b89..2ef5c7f 100644 --- a/source/dub/test/base.d +++ b/source/dub/test/base.d @@ -694,19 +694,27 @@ /// Ditto public void writeFile (NativePath path, const(ubyte)[] data) { + enforce(!path.endsWithSlash(), + "Cannot write to directory: " ~ path.toNativeString()); if (auto file = this.lookup(path)) { + // If the file already exists, override it enforce(file.type == Type.File, "Trying to write to directory: " ~ path.toNativeString()); file.content = data.dup; - } else { + } else if (path.hasParentPath()) { + // If we're not in the right `FSEntry`, recurse auto parentPath = path.parentPath(); auto parent = this.lookup(parentPath); - enforce(parent !is null, "No such directory: " ~ parentPath.toNativeString()); + enforce(parent !is null, + "No such directory: " ~ parentPath.toNativeString()); enforce(parent.type == Type.Directory, "Parent path is not a directory: " ~ parentPath.toNativeString()); + return parent.writeFile(NativePath(path.head), data); + } else { + // We're in the right `FSEntry`, create the file auto file = new FSEntry(parent, Type.File, path.head.name()); file.content = data.dup; - parent.children ~= file; + this.children ~= file; } } }