Skip to content

NativeFileSystem with an absolute base path mounted at / resolves wrong virtual paths #33

Description

@JanSimek

After v2.1.1, FileInfo::Configure() strips aliasPath before basePath. Because
aliasPath is checked with fileName.find(aliasPath) == 0, a root alias of "/" matches every
absolute path (they all start with /). As a result, a NativeFileSystem created with an absolute
base path and mounted at alias "/" no longer strips the base path, so every file's VirtualPath()
becomes its full absolute path instead of the intended alias-relative path. Files can no longer be
opened by their virtual path.

See commit 487b922 in include/vfspp/FileInfo.hpp:

 void Configure(const std::string& aliasPath, const std::string& basePath, const std::string& fileName)
 {
-    // Remove alias path from file name if any
     std::string strippedFileName = fileName;
-    if (!basePath.empty() && fileName.find(basePath) == 0) {
+    if (!aliasPath.empty() && fileName.find(aliasPath) == 0) {
+        strippedFileName = fileName.substr(aliasPath.length());
+    } else if (!basePath.empty() && fileName.find(basePath) == 0) {
         strippedFileName = fileName.substr(basePath.length());
     }

Minimal reproduction

#include <vfspp/FileInfo.hpp>
#include <cassert>

int main()
{
    // alias "/", an ABSOLUTE base path, and a file discovered under it
    // (this is exactly what NativeFileSystem builds for each entry).
    vfspp::FileInfo info("/", "/home/user/game", "/home/user/game/data/maps/arvillag.map");

    // Expected: base path stripped, alias prepended.
    //   v2.1.1  -> "/data/maps/arvillag.map"                      (correct)
    //   master  -> "/home/user/game/data/maps/arvillag.map"      (base path NOT stripped)
    assert(info.VirtualPath() == "/data/maps/arvillag.map");
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions