From: František Dvořák Date: Sat, 19 Oct 2013 19:15:59 +0000 (+0200) Subject: Cleanup around parent paths evaluation. "." is replaced by full current working direc... X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=9f67d80c884c01ece169fb4fa69548e5af0134af;p=dmlite-plugins-vfs.git Cleanup around parent paths evaluation. "." is replaced by full current working directory, other relative paths are untouched. --- 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); }