summaryrefslogtreecommitdiff
path: root/AK/FileSystemPath.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2018-11-18 14:57:41 +0100
committerAndreas Kling <awesomekling@gmail.com>2018-11-18 15:02:16 +0100
commitde4604ac95261fe95f5921b0d16ee65fb501332a (patch)
tree16bf9be7e4d94862179c99d5cdcee29a0b7ca744 /AK/FileSystemPath.cpp
parent303577df16cf990d1c0cb2c83cd8a954258809ba (diff)
downloadserenity-de4604ac95261fe95f5921b0d16ee65fb501332a.zip
Finally hook up the mkdir code to a syscall.
Added a /bin/mkdir that makes directories. How very neat :^) There are various limitations because of missing functionality.
Diffstat (limited to 'AK/FileSystemPath.cpp')
-rw-r--r--AK/FileSystemPath.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/AK/FileSystemPath.cpp b/AK/FileSystemPath.cpp
index 88dce0aa56..fcba78420e 100644
--- a/AK/FileSystemPath.cpp
+++ b/AK/FileSystemPath.cpp
@@ -30,15 +30,32 @@ bool FileSystemPath::canonicalize(bool resolveSymbolicLinks)
canonicalParts.append(part);
}
if (canonicalParts.isEmpty()) {
- m_string = "/";
+ m_string = m_basename = m_dirname = "/";
return true;
}
- StringBuilder builder;
- for (auto& cpart : canonicalParts) {
- builder.append('/');
- builder.append(move(cpart));
+
+ m_basename = canonicalParts.last();
+
+ if (canonicalParts.size() == 1) {
+ m_dirname = "/";
+ } else {
+ StringBuilder builder;
+ for (size_t i = 0; i < canonicalParts.size() - 1; ++i) {
+ auto& cpart = canonicalParts[i];
+ builder.append('/');
+ builder.append(cpart);
+ }
+ m_dirname = builder.build();
+ }
+
+ {
+ StringBuilder builder;
+ for (auto& cpart : canonicalParts) {
+ builder.append('/');
+ builder.append(move(cpart));
+ }
+ m_string = builder.build();
}
- m_string = builder.build();
return true;
}