From f03cf6a88f9c0e595ba88dccc7f6aeb635919676 Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Sat, 8 Feb 2025 22:03:19 -0400 Subject: [PATCH] love.filesystem mount APIs return false if the path is already mounted. Fixes #2153. --- src/modules/filesystem/physfs/Filesystem.cpp | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/modules/filesystem/physfs/Filesystem.cpp b/src/modules/filesystem/physfs/Filesystem.cpp index ad7777e0f..14c2ca43e 100644 --- a/src/modules/filesystem/physfs/Filesystem.cpp +++ b/src/modules/filesystem/physfs/Filesystem.cpp @@ -106,6 +106,27 @@ static bool isAppCommonPath(Filesystem::CommonPath path) } } +static bool isMounted(const std::string &path) +{ + char **mountedpaths = PHYSFS_getSearchPath(); + if (mountedpaths == nullptr) + return false; + + bool mounted = false; + for (char **p = mountedpaths; *p != nullptr; p++) + { + char *mountedpath = *p; + if (strcmp(path.c_str(), mountedpath) == 0) + { + mounted = true; + break; + } + } + + PHYSFS_freeList(mountedpaths); + return mounted; +} + Filesystem::Filesystem() : love::filesystem::Filesystem("love.filesystem.physfs") , appendIdentityToPath(false) @@ -292,6 +313,9 @@ bool Filesystem::setSource(const char *source) } #endif + if (isMounted(new_search_path)) + return false; + // Add the directory. if (!PHYSFS_mount(new_search_path.c_str(), nullptr, 1)) { @@ -398,6 +422,9 @@ bool Filesystem::mountFullPath(const char *archive, const char *mountpoint, Moun std::string canonarchive = canonicalizeRealPath(archive); + if (isMounted(canonarchive)) + return false; + #ifdef LOVE_ANDROID if (strncmp(archive, "content://", 10) == 0) { @@ -455,6 +482,9 @@ bool Filesystem::mount(Data *data, const char *archivename, const char *mountpoi if (!PHYSFS_isInit()) return false; + if (isMounted(archivename)) + return false; + if (PHYSFS_mountMemory(data->getData(), data->getSize(), nullptr, archivename, mountpoint, appendToPath) != 0) { mountedData[archivename] = data;