diff --git a/src/lib/seallib/vfs.cpp b/src/lib/seallib/vfs.cpp index 29ed82e..578fa21 100644 --- a/src/lib/seallib/vfs.cpp +++ b/src/lib/seallib/vfs.cpp @@ -257,6 +257,28 @@ std::string VirtualFileSystem::trimPathSeparators(const std::string& path) return path.substr(start, end - start + 1); } +bool VirtualFileSystem::getRelativePath(const MountPoint& mount, const std::string& searchPath, + std::string& outRelative) const +{ + if (searchPath == mount.virtualPath) + { + outRelative = "/"; + return true; + } + if (mount.virtualPath == "/") + { + outRelative = searchPath; + return true; + } + std::string prefix = mount.virtualPath + '/'; + if (searchPath.compare(0, prefix.length(), prefix) == 0) + { + outRelative = searchPath.substr(prefix.length()); + return true; + } + return false; +} + /* mountpoint */ diff --git a/src/lib/seallib/vfs.h b/src/lib/seallib/vfs.h index fe2e47e..ebfd4d8 100644 --- a/src/lib/seallib/vfs.h +++ b/src/lib/seallib/vfs.h @@ -99,6 +99,9 @@ namespace seallib static bool isPathSeparator(char c); static std::string trimPathSeparators(const std::string& path); + + bool getRelativePath(const MountPoint& mount, const std::string& searchPath, + std::string& outRelative) const; }; inline std::string vfsResultToString(VFSResult result)