From 7566db14f2edc14b8ac4939557f4c3656d4bbb89 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 6 Aug 2017 00:53:49 -0300 Subject: [PATCH] love.filesystem.isFile and isDirectory behave consistently between PhysFS 2.0 and 2.1/3.0 (see issue #641). --HG-- branch : minor --- src/modules/filesystem/physfs/Filesystem.cpp | 12 ++++++++++-- src/modules/image/wrap_Image.cpp | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/modules/filesystem/physfs/Filesystem.cpp b/src/modules/filesystem/physfs/Filesystem.cpp index b4660e0e5..90cbf64ae 100644 --- a/src/modules/filesystem/physfs/Filesystem.cpp +++ b/src/modules/filesystem/physfs/Filesystem.cpp @@ -586,7 +586,7 @@ bool Filesystem::isDirectory(const char *dir) const else return false; #else - return PHYSFS_isDirectory(dir) != 0; + return PHYSFS_isDirectory(dir) != 0 && !isSymlink(dir); #endif } @@ -595,7 +595,15 @@ bool Filesystem::isFile(const char *file) const if (!PHYSFS_isInit()) return false; - return PHYSFS_exists(file) && !isDirectory(file); +#ifdef LOVE_USE_PHYSFS_2_1 + PHYSFS_Stat stat = {}; + if (PHYSFS_stat(file, &stat)) + return stat.filetype == PHYSFS_FILETYPE_REGULAR; + else + return false; +#else + return PHYSFS_exists(file) && !isDirectory(file) && !isSymlink(file); +#endif } bool Filesystem::isSymlink(const char *filename) const diff --git a/src/modules/image/wrap_Image.cpp b/src/modules/image/wrap_Image.cpp index c9ec075a6..024491300 100644 --- a/src/modules/image/wrap_Image.cpp +++ b/src/modules/image/wrap_Image.cpp @@ -83,7 +83,7 @@ int w_newImageData(lua_State *L) t->release(); return 1; } - else if (filesystem::luax_cangetfiledata(L, 1) || luax_istype(L, 1, Data::type)) // Case 2: File(Data). + else if (filesystem::luax_cangetdata(L, 1)) // Case 2: File(Data). { Data *data = love::filesystem::luax_getdata(L, 1);