diff options
author | Justin DeMartino <jjdemartino@google.com> | 2020-10-14 19:39:53 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-10-14 19:39:53 +0000 |
commit | 0d11af03e43f110b0bb160f7e20436d0043e3038 (patch) | |
tree | 48f8bcca856276ec73a86dd3fb26143d3ca64578 /fs_mgr/libfiemap/utility.cpp | |
parent | 075666ebd0dee8d0c4a2efa54f7c324a3f67ee2a (diff) | |
parent | a6c01e4e98d2b343dcecfc99611e2e6250c730db (diff) |
Merge changes from topic "SP1A.200921.001" into s-keystone-qcom-dev
* changes:
fs_mgr: adb-remount-test.sh: filter out more administrivia mounts.
Merge SP1A.200921.001 Change-Id: I90b97c4e9fb10b1f45e74def404823eed5b1aaa8
Diffstat (limited to 'fs_mgr/libfiemap/utility.cpp')
-rw-r--r-- | fs_mgr/libfiemap/utility.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/fs_mgr/libfiemap/utility.cpp b/fs_mgr/libfiemap/utility.cpp index c1898556e..54cf1836b 100644 --- a/fs_mgr/libfiemap/utility.cpp +++ b/fs_mgr/libfiemap/utility.cpp @@ -167,5 +167,30 @@ bool FilesystemHasReliablePinning(const std::string& file, bool* supported) { return F2fsPinBeforeAllocate(fd, supported); } +bool IsSubdir(const std::string& child, const std::string& parent) { + // Precondition: both are absolute paths. + CHECK(android::base::StartsWith(child, "/")) << "Not an absolute path: " << child; + CHECK(android::base::StartsWith(parent, "/")) << "Not an absolute path: " << parent; + + // Remove extraneous "/" at the end. + std::string_view child_sv = child; + while (child_sv != "/" && android::base::ConsumeSuffix(&child_sv, "/")) + ; + + std::string_view parent_sv = parent; + while (parent_sv != "/" && android::base::ConsumeSuffix(&parent_sv, "/")) + ; + + // IsSubdir(anything, "/") => true + if (parent_sv == "/") return true; + + // IsSubdir("/foo", "/foo") => true + if (parent_sv == child_sv) return true; + + // IsSubdir("/foo/bar", "/foo") => true + // IsSubdir("/foo-bar", "/foo") => false + return android::base::StartsWith(child_sv, std::string(parent_sv) + "/"); +} + } // namespace fiemap } // namespace android |