Browse Source

Re-added love.filesystem.exists.

If PhysFS 2.1-alpha is used and a directory is symlinked, isDirectory will return false (whereas it will return true when PhysFS 2.0 is used.) exists will return true in all cases.
Alex Szpakowski 9 years ago
parent
commit
de0b63a48d

+ 0 - 1
changes.txt

@@ -79,7 +79,6 @@ Released: N/A
   * Renamed Canvas:getImageData to Canvas:newImageData.
   * Renamed Canvas:getImageData to Canvas:newImageData.
   * Renamed love.image's CompressedData type to CompressedImageData.
   * Renamed love.image's CompressedData type to CompressedImageData.
 
 
-  * Removed love.filesystem.exists (use love.filesystem.isFile or love.filesystem.isDirectory instead.)
   * Removed callback variant of love.filesystem.getDirectoryItems.
   * Removed callback variant of love.filesystem.getDirectoryItems.
   * Removed the "wu" and "wd" constants for love.mousepressed (replaced by love.wheelmoved.)
   * Removed the "wu" and "wd" constants for love.mousepressed (replaced by love.wheelmoved.)
   * Removed the named mouse button constants (replaced by button numbers.)
   * Removed the named mouse button constants (replaced by button numbers.)

+ 12 - 6
src/modules/filesystem/Filesystem.h

@@ -156,6 +156,12 @@ public:
 	 **/
 	 **/
 	virtual std::string getRealDirectory(const char *filename) const = 0;
 	virtual std::string getRealDirectory(const char *filename) const = 0;
 
 
+	/**
+	 * Checks if a path exists.
+	 * @param path The path to check.
+	 **/
+	virtual bool exists(const char *path) const = 0;
+
 	/**
 	/**
 	 * Checks if a path is a directory.
 	 * Checks if a path is a directory.
 	 * @param dir The directory name to check.
 	 * @param dir The directory name to check.
@@ -168,6 +174,12 @@ public:
 	 **/
 	 **/
 	virtual bool isFile(const char *file) const = 0;
 	virtual bool isFile(const char *file) const = 0;
 
 
+	/**
+	 * Gets whether a filepath is actually a symlink.
+	 * Always returns false if symlinks are not enabled.
+	 **/
+	virtual bool isSymlink(const char *filename) const = 0;
+
 	/**
 	/**
 	 * Creates a directory. Write dir must be set.
 	 * Creates a directory. Write dir must be set.
 	 * @param dir The directory to create.
 	 * @param dir The directory to create.
@@ -232,12 +244,6 @@ public:
 	 **/
 	 **/
 	virtual bool areSymlinksEnabled() const = 0;
 	virtual bool areSymlinksEnabled() const = 0;
 
 
-	/**
-	 * Gets whether a filepath is actually a symlink.
-	 * Always returns false if symlinks are not enabled.
-	 **/
-	virtual bool isSymlink(const char *filename) const = 0;
-
 	// Require path accessors
 	// Require path accessors
 	// Not const because it's R/W
 	// Not const because it's R/W
 	virtual std::vector<std::string> &getRequirePath() = 0;
 	virtual std::vector<std::string> &getRequirePath() = 0;

+ 18 - 13
src/modules/filesystem/physfs/Filesystem.cpp

@@ -579,6 +579,11 @@ std::string Filesystem::getRealDirectory(const char *filename) const
 	return std::string(dir);
 	return std::string(dir);
 }
 }
 
 
+bool Filesystem::exists(const char *path) const
+{
+	return PHYSFS_exists(path) != 0;
+}
+
 bool Filesystem::isDirectory(const char *dir) const
 bool Filesystem::isDirectory(const char *dir) const
 {
 {
 #ifdef LOVE_USE_PHYSFS_2_1
 #ifdef LOVE_USE_PHYSFS_2_1
@@ -597,6 +602,19 @@ bool Filesystem::isFile(const char *file) const
 	return PHYSFS_exists(file) && !isDirectory(file);
 	return PHYSFS_exists(file) && !isDirectory(file);
 }
 }
 
 
+bool Filesystem::isSymlink(const char *filename) const
+{
+#ifdef LOVE_USE_PHYSFS_2_1
+	PHYSFS_Stat stat = {};
+	if (PHYSFS_stat(filename, &stat))
+		return stat.filetype == PHYSFS_FILETYPE_SYMLINK;
+	else
+		return false;
+#else
+	return PHYSFS_isSymbolicLink(filename) != 0;
+#endif
+}
+
 bool Filesystem::createDirectory(const char *dir)
 bool Filesystem::createDirectory(const char *dir)
 {
 {
 	if (PHYSFS_getWriteDir() == 0 && !setupWriteDirectory())
 	if (PHYSFS_getWriteDir() == 0 && !setupWriteDirectory())
@@ -705,19 +723,6 @@ bool Filesystem::areSymlinksEnabled() const
 	return PHYSFS_symbolicLinksPermitted() != 0;
 	return PHYSFS_symbolicLinksPermitted() != 0;
 }
 }
 
 
-bool Filesystem::isSymlink(const char *filename) const
-{
-#ifdef LOVE_USE_PHYSFS_2_1
-	PHYSFS_Stat stat = {};
-	if (PHYSFS_stat(filename, &stat))
-		return stat.filetype == PHYSFS_FILETYPE_SYMLINK;
-	else
-		return false;
-#else
-	return PHYSFS_isSymbolicLink(filename) != 0;
-#endif
-}
-
 std::vector<std::string> &Filesystem::getRequirePath()
 std::vector<std::string> &Filesystem::getRequirePath()
 {
 {
 	return requirePath;
 	return requirePath;

+ 2 - 1
src/modules/filesystem/physfs/Filesystem.h

@@ -75,8 +75,10 @@ public:
 
 
 	std::string getRealDirectory(const char *filename) const;
 	std::string getRealDirectory(const char *filename) const;
 
 
+	bool exists(const char *path) const;
 	bool isDirectory(const char *dir) const;
 	bool isDirectory(const char *dir) const;
 	bool isFile(const char *file) const;
 	bool isFile(const char *file) const;
+	bool isSymlink(const char *filename) const;
 
 
 	bool createDirectory(const char *dir);
 	bool createDirectory(const char *dir);
 
 
@@ -93,7 +95,6 @@ public:
 
 
 	void setSymlinksEnabled(bool enable);
 	void setSymlinksEnabled(bool enable);
 	bool areSymlinksEnabled() const;
 	bool areSymlinksEnabled() const;
-	bool isSymlink(const char *filename) const;
 
 
 	std::vector<std::string> &getRequirePath();
 	std::vector<std::string> &getRequirePath();
 
 

+ 16 - 8
src/modules/filesystem/wrap_Filesystem.cpp

@@ -316,6 +316,13 @@ int w_getExecutablePath(lua_State *L)
 	return 1;
 	return 1;
 }
 }
 
 
+int w_exists(lua_State *L)
+{
+	const char *arg = luaL_checkstring(L, 1);
+	luax_pushboolean(L, instance()->exists(arg));
+	return 1;
+}
+
 int w_isDirectory(lua_State *L)
 int w_isDirectory(lua_State *L)
 {
 {
 	const char *arg = luaL_checkstring(L, 1);
 	const char *arg = luaL_checkstring(L, 1);
@@ -330,6 +337,13 @@ int w_isFile(lua_State *L)
 	return 1;
 	return 1;
 }
 }
 
 
+int w_isSymlink(lua_State *L)
+{
+	const char *filename = luaL_checkstring(L, 1);
+	luax_pushboolean(L, instance()->isSymlink(filename));
+	return 1;
+}
+
 int w_createDirectory(lua_State *L)
 int w_createDirectory(lua_State *L)
 {
 {
 	const char *arg = luaL_checkstring(L, 1);
 	const char *arg = luaL_checkstring(L, 1);
@@ -551,13 +565,6 @@ int w_areSymlinksEnabled(lua_State *L)
 	return 1;
 	return 1;
 }
 }
 
 
-int w_isSymlink(lua_State *L)
-{
-	const char *filename = luaL_checkstring(L, 1);
-	luax_pushboolean(L, instance()->isSymlink(filename));
-	return 1;
-}
-
 int w_getRequirePath(lua_State *L)
 int w_getRequirePath(lua_State *L)
 {
 {
 	std::stringstream path;
 	std::stringstream path;
@@ -715,8 +722,10 @@ static const luaL_Reg functions[] =
 	{ "getSourceBaseDirectory", w_getSourceBaseDirectory },
 	{ "getSourceBaseDirectory", w_getSourceBaseDirectory },
 	{ "getRealDirectory", w_getRealDirectory },
 	{ "getRealDirectory", w_getRealDirectory },
 	{ "getExecutablePath", w_getExecutablePath },
 	{ "getExecutablePath", w_getExecutablePath },
+	{ "exists", w_exists },
 	{ "isDirectory", w_isDirectory },
 	{ "isDirectory", w_isDirectory },
 	{ "isFile", w_isFile },
 	{ "isFile", w_isFile },
+	{ "isSymlink", w_isSymlink },
 	{ "createDirectory", w_createDirectory },
 	{ "createDirectory", w_createDirectory },
 	{ "remove", w_remove },
 	{ "remove", w_remove },
 	{ "read", w_read },
 	{ "read", w_read },
@@ -729,7 +738,6 @@ static const luaL_Reg functions[] =
 	{ "getSize", w_getSize },
 	{ "getSize", w_getSize },
 	{ "setSymlinksEnabled", w_setSymlinksEnabled },
 	{ "setSymlinksEnabled", w_setSymlinksEnabled },
 	{ "areSymlinksEnabled", w_areSymlinksEnabled },
 	{ "areSymlinksEnabled", w_areSymlinksEnabled },
-	{ "isSymlink", w_isSymlink },
 	{ "newFileData", w_newFileData },
 	{ "newFileData", w_newFileData },
 	{ "getRequirePath", w_getRequirePath },
 	{ "getRequirePath", w_getRequirePath },
 	{ "setRequirePath", w_setRequirePath },
 	{ "setRequirePath", w_setRequirePath },