From e4e8f141b6a8a3a10bb8d93d06cd37aa60216e7e Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sat, 1 Sep 2018 01:56:20 -0500 Subject: [PATCH] [ox/fs] Fix -p write --- deps/ox/src/ox/fs/filesystem2/directory.hpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/deps/ox/src/ox/fs/filesystem2/directory.hpp b/deps/ox/src/ox/fs/filesystem2/directory.hpp index 519f3cb5..17cd29c2 100644 --- a/deps/ox/src/ox/fs/filesystem2/directory.hpp +++ b/deps/ox/src/ox/fs/filesystem2/directory.hpp @@ -103,6 +103,9 @@ class Directory { Error mkdir(PathIterator path, bool parents, FileName *nameBuff = nullptr); + /** + * @param parents indicates the operation should create non-existent directories in the path, like mkdir -p + */ Error write(PathIterator it, InodeId_t inode, bool parents = false, FileName *nameBuff = nullptr) noexcept; Error remove(PathIterator it, FileName *nameBuff = nullptr) noexcept; @@ -195,13 +198,18 @@ Error Directory::write(PathIterator path, InodeId_t inode, bool paren oxReturnError(path.get(name)); nextChild = find(*name); + if (!nextChild && parents) { + oxReturnError(Directory(m_fs, nextChild).init()); + nextChild = find(*name); + } else { + return OxError(1); + } + if (nextChild) { // reuse name because it is a rather large variable and will not be used again // be attentive that this remains true name = nullptr; return Directory(m_fs, nextChild).write(path + 1, inode, parents, nameBuff); - } else if (parents) { - Directory(m_fs, nextChild).init(); } } else { // insert the new entry on this directory