From 4a0d387328dd4df97eec8de334d2560e5e194953 Mon Sep 17 00:00:00 2001 From: neru Date: Mon, 11 May 2026 08:07:12 -0300 Subject: [PATCH] feat: add getRelativePath --- src/lib/seallib/vfs.cpp | 22 ++++++++++++++++++++++ src/lib/seallib/vfs.h | 3 +++ 2 files changed, 25 insertions(+) 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)