diff --git a/src/lib/seallib/vfs.cpp b/src/lib/seallib/vfs.cpp index 82a241a..29ed82e 100644 --- a/src/lib/seallib/vfs.cpp +++ b/src/lib/seallib/vfs.cpp @@ -87,20 +87,32 @@ void VirtualFileSystem::unmountAll() bool VirtualFileSystem::exists(const std::string& path) const { std::shared_lock lock(_mutex); - std::string relativePath; - const MountPoint* mount = findBestMount(path, relativePath); + std::string searchPath = trimPathSeparators(normalizePath(path)); - return mount ? mount->provider->exists(relativePath) : false; + for (const auto& mount : _mounts) + { + std::string relativePath; + if (getRelativePath(mount, searchPath, relativePath)) + { + if (mount.provider->exists(relativePath)) return true; + } + } + return false; } VFSResult VirtualFileSystem::readFile(const std::string& path, FileBuffer& outBuffer) const { std::shared_lock lock(_mutex); - std::string relativePath; - const MountPoint* mount = findBestMount(path, relativePath); + std::string searchPath = trimPathSeparators(normalizePath(path)); - if (!mount) return VFSResult::FileNotFound; - return mount->provider->readFile(relativePath, outBuffer); + for (const auto& mount : _mounts) + { + std::string relativePath; + if (getRelativePath(mount, searchPath, relativePath)) + if (mount.provider->exists(relativePath)) return mount.provider->readFile(relativePath, outBuffer); + } + + return VFSResult::FileNotFound; } VFSResult VirtualFileSystem::writeFile(const std::string& path, const FileBuffer& buffer) @@ -118,11 +130,16 @@ VFSResult VirtualFileSystem::writeFile(const std::string& path, const FileBuffer VFSResult VirtualFileSystem::deleteFile(const std::string& path) { std::shared_lock lock(_mutex); - std::string relativePath; - MountPoint* mount = findBestMount(path, relativePath); + std::string searchPath = trimPathSeparators(normalizePath(path)); - if (!mount) return VFSResult::FileNotFound; - return mount->provider->deleteFile(relativePath); + for (auto& mount : _mounts) + { + std::string relativePath; + if (getRelativePath(mount, searchPath, relativePath)) + if (mount.provider->exists(relativePath)) return mount.provider->deleteFile(relativePath); + } + + return VFSResult::FileNotFound; } VFSResult VirtualFileSystem::createDirectory(const std::string& path)