From 9f67d80c884c01ece169fb4fa69548e5af0134af Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Sat, 19 Oct 2013 21:15:59 +0200 Subject: [PATCH] Cleanup around parent paths evaluation. "." is replaced by full current working directory, other relative paths are untouched. --- src/VfsNs.cpp | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/VfsNs.cpp b/src/VfsNs.cpp index 35d4db4..4ccad7a 100644 --- a/src/VfsNs.cpp +++ b/src/VfsNs.cpp @@ -919,6 +919,8 @@ ExtendedStat VfsCatalog::getParent(const std::string& path, std::string* parentPath, std::string* name) throw (DmException) { + bool absPath; + if (path.empty()) vfsThrow(EINVAL, "empty path"); @@ -927,15 +929,35 @@ ExtendedStat VfsCatalog::getParent(const std::string& path, *name = components.back(); components.pop_back(); - if (components.size() == 1 && components[0] == "/") *parentPath = "/"; - else *parentPath = Url::joinPath(components); - - // Get the files now - if (!parentPath->empty()) { - return this->vfsExtendedStat(*parentPath); + absPath = (path.size() >= 1 && path[0] == '/'); + if (components.size() == 0) { + // + // Root directory or relative directory without subdirectories: + // / + // name + // + // We can't check parent of root. + // Single name is relative path with parent ".". + // + *parentPath = absPath ? "/" : this->getWorkingDir(); } else { - return this->vfsExtendedStat(this->getWorkingDir()); + // + // At least one directory: + // /name + // dir/name + // + // Single "/" would be removed by Url:joinPath(). + // + if (components.size() == 1 && absPath) { + *parentPath = "/"; + } else { + *parentPath = Url::joinPath(components); + } } + + if (parentPath->empty()) *parentPath = "."; + + return this->vfsExtendedStat(*parentPath); } -- 1.8.2.3