std::string* parentPath,
std::string* name) throw (DmException)
{
+ bool absPath;
+
if (path.empty())
vfsThrow(EINVAL, "empty 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);
}