diff --git a/src/modules/filesystem/physfs/Filesystem.cpp b/src/modules/filesystem/physfs/Filesystem.cpp index 4c355c06f..71c6e4cbd 100644 --- a/src/modules/filesystem/physfs/Filesystem.cpp +++ b/src/modules/filesystem/physfs/Filesystem.cpp @@ -661,6 +661,21 @@ int64 Filesystem::getSize(const char *filename) const return size; } +void Filesystem::setSymlinksEnabled(bool enable) +{ + PHYSFS_permitSymbolicLinks(enable ? 1 : 0); +} + +bool Filesystem::areSymlinksEnabled() const +{ + return PHYSFS_symbolicLinksPermitted() != 0; +} + +bool Filesystem::isSymlink(const char *filename) const +{ + return PHYSFS_isSymbolicLink(filename) != 0; +} + } // physfs } // filesystem } // love diff --git a/src/modules/filesystem/physfs/Filesystem.h b/src/modules/filesystem/physfs/Filesystem.h index 2f036a87f..8c2f96209 100644 --- a/src/modules/filesystem/physfs/Filesystem.h +++ b/src/modules/filesystem/physfs/Filesystem.h @@ -247,6 +247,22 @@ public: **/ int64 getSize(const char *filename) const; + /** + * Enable or disable symbolic link support in love.filesystem. + **/ + void setSymlinksEnabled(bool enable); + + /** + * Gets whether symbolic link support is enabled. + **/ + bool areSymlinksEnabled() const; + + /** + * Gets whether a filepath is actually a symlink. + * Always returns false if symlinks are not enabled. + **/ + bool isSymlink(const char *filename) const; + /** * Text file line-reading iterator function used and * pushed on the Lua stack by love.filesystem.lines diff --git a/src/modules/filesystem/wrap_Filesystem.cpp b/src/modules/filesystem/wrap_Filesystem.cpp index 5ece03b13..d8e83b256 100644 --- a/src/modules/filesystem/wrap_Filesystem.cpp +++ b/src/modules/filesystem/wrap_Filesystem.cpp @@ -486,6 +486,25 @@ int w_getSize(lua_State *L) return 1; } +int w_setSymlinksEnabled(lua_State *L) +{ + instance()->setSymlinksEnabled(luax_toboolean(L, 1)); + return 0; +} + +int w_areSymlinksEnabled(lua_State *L) +{ + luax_pushboolean(L, instance()->areSymlinksEnabled()); + return 1; +} + +int w_isSymlink(lua_State *L) +{ + const char *filename = luaL_checkstring(L, 1); + luax_pushboolean(L, instance()->isSymlink(filename)); + return 1; +} + int loader(lua_State *L) { const char *filename = lua_tostring(L, -1); @@ -645,6 +664,9 @@ static const luaL_Reg functions[] = { "load", w_load }, { "getLastModified", w_getLastModified }, { "getSize", w_getSize }, + { "setSymlinksEnabled", w_setSymlinksEnabled }, + { "areSymlinksEnabled", w_areSymlinksEnabled }, + { "isSymlink", w_isSymlink }, { "newFileData", w_newFileData }, { 0, 0 } }; diff --git a/src/modules/filesystem/wrap_Filesystem.h b/src/modules/filesystem/wrap_Filesystem.h index e11a88c40..eb50dbf9a 100644 --- a/src/modules/filesystem/wrap_Filesystem.h +++ b/src/modules/filesystem/wrap_Filesystem.h @@ -71,6 +71,9 @@ int w_lines(lua_State *L); int w_load(lua_State *L); int w_getLastModified(lua_State *L); int w_getSize(lua_State *L); +int w_setSymlinksEnabled(lua_State *L); +int w_areSymlinksEnabled(lua_State *L); +int w_isSymlink(lua_State *L); int loader(lua_State *L); int extloader(lua_State *L); extern "C" LOVE_EXPORT int luaopen_love_filesystem(lua_State *L);