aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/fs/chroot/chroot-fs.cpp15
-rw-r--r--backends/fs/chroot/chroot-fs.h3
-rw-r--r--common/str.cpp12
-rw-r--r--common/str.h5
4 files changed, 17 insertions, 18 deletions
diff --git a/backends/fs/chroot/chroot-fs.cpp b/backends/fs/chroot/chroot-fs.cpp
index 7cdd800dac..1c3e3b545f 100644
--- a/backends/fs/chroot/chroot-fs.cpp
+++ b/backends/fs/chroot/chroot-fs.cpp
@@ -39,7 +39,7 @@ ChRootFilesystemNode::ChRootFilesystemNode(const Common::String &root, POSIXFile
ChRootFilesystemNode::ChRootFilesystemNode(const Common::String &root, const Common::String &path) {
_root = Common::normalizePath(root, '/');
- _realNode = new POSIXFilesystemNode(root.stringByAppendingPathComponent(path));
+ _realNode = new POSIXFilesystemNode(addPathComponent(root, path));
}
ChRootFilesystemNode::~ChRootFilesystemNode() {
@@ -108,4 +108,17 @@ Common::WriteStream *ChRootFilesystemNode::createWriteStream() {
return _realNode->createWriteStream();
}
+Common::String ChRootFilesystemNode::addPathComponent(const Common::String &path, const Common::String &component) {
+ const char sep = '/';
+ if (path.lastChar() == sep && component.firstChar() == sep) {
+ return Common::String::format("%s%s", path.c_str(), component.c_str() + 1);
+ }
+
+ if (path.lastChar() == sep || component.firstChar() == sep) {
+ return Common::String::format("%s%s", path.c_str(), component.c_str());
+ }
+
+ return Common::String::format("%s%c%s", path.c_str(), sep, component.c_str());
+}
+
#endif
diff --git a/backends/fs/chroot/chroot-fs.h b/backends/fs/chroot/chroot-fs.h
index 2d4c3eb9dd..c330123bb5 100644
--- a/backends/fs/chroot/chroot-fs.h
+++ b/backends/fs/chroot/chroot-fs.h
@@ -49,6 +49,9 @@ public:
virtual Common::SeekableReadStream *createReadStream();
virtual Common::WriteStream *createWriteStream();
+
+private:
+ static Common::String addPathComponent(const Common::String &path, const Common::String &component);
};
#endif /* CHROOT_FS_H */
diff --git a/common/str.cpp b/common/str.cpp
index ad02bfdaf8..faf84d722f 100644
--- a/common/str.cpp
+++ b/common/str.cpp
@@ -665,18 +665,6 @@ String lastPathComponent(const String &path, const char sep) {
return String(first, last);
}
-String String::stringByAppendingPathComponent(String component, char sep) const {
- if (lastChar() == sep && component.firstChar() == sep) {
- return String::format("%s%s", c_str(), component.c_str() + 1);
- }
-
- if (lastChar() == sep || component.firstChar() == sep) {
- return String::format("%s%s", c_str(), component.c_str());
- }
-
- return String::format("%s%c%s", c_str(), sep, component.c_str());
-}
-
String normalizePath(const String &path, const char sep) {
if (path.empty())
return path;
diff --git a/common/str.h b/common/str.h
index f156290e94..a30dae3513 100644
--- a/common/str.h
+++ b/common/str.h
@@ -218,11 +218,6 @@ public:
*/
void trim();
- /**
- * Add a path component
- */
- String stringByAppendingPathComponent(String component, char sep = '/') const;
-
uint hash() const;
/**