summaryrefslogtreecommitdiff
path: root/services/incremental/path.cpp
diff options
context:
space:
mode:
authorYurii Zubrytskyi <zyy@google.com>2020-01-10 11:53:24 -0800
committerYurii Zubrytskyi <zyy@google.com>2020-01-28 12:10:17 -0800
commit4a25dfb2de3cf0f6dd81f4add3fd905db0834a38 (patch)
treefb36a044655007025be9e3fa8fb189281ac9698c /services/incremental/path.cpp
parent092993a72d710b7f5cb0f53aed736fd2675345e3 (diff)
Port the current code to new IncFS
Bug: 146080380 Test: manual, "cmd incremental install-start" Change-Id: I6761c3f0e58b6d4de1ae3c4b31c23204fba9f740
Diffstat (limited to 'services/incremental/path.cpp')
-rw-r--r--services/incremental/path.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/services/incremental/path.cpp b/services/incremental/path.cpp
index c529d61abd15..0d86f2a984d6 100644
--- a/services/incremental/path.cpp
+++ b/services/incremental/path.cpp
@@ -44,16 +44,45 @@ bool PathLess::operator()(std::string_view l, std::string_view r) const {
PathCharsLess());
}
+static void preparePathComponent(std::string_view path, bool trimFront) {
+ if (trimFront) {
+ while (!path.empty() && path.front() == '/') {
+ path.remove_prefix(1);
+ }
+ }
+ while (!path.empty() && path.back() == '/') {
+ path.remove_suffix(1);
+ }
+}
+
void details::append_next_path(std::string& target, std::string_view path) {
+ preparePathComponent(path, true);
if (path.empty()) {
return;
}
- if (!target.empty()) {
+ if (!target.empty() && !target.ends_with('/')) {
target.push_back('/');
}
target += path;
}
+std::string_view relativize(std::string_view parent, std::string_view nested) {
+ if (!nested.starts_with(parent)) {
+ return nested;
+ }
+ if (nested.size() == parent.size()) {
+ return {};
+ }
+ if (nested[parent.size()] != '/') {
+ return nested;
+ }
+ auto relative = nested.substr(parent.size());
+ while (relative.front() == '/') {
+ relative.remove_prefix(1);
+ }
+ return relative;
+}
+
bool isAbsolute(std::string_view path) {
return !path.empty() && path[0] == '/';
}