فهرست منبع

[php][php7] throw on failed FileSystem.deleteFile() and deleteDirectory() (#5869)

* [php][php7] throw on failed FileSystem.deleteFile() and deleteDirectory() (fixes #5742)

* fix conditionals in Issue5742

* [cs] throw on FileSystem.deleteDirectory(path) and deleteFile(path) if path does not exist

* [cs] fix existance check in FileSystem.deleteDirectory()

* [lua] add luafilesystem to dependencies in RunCi
Alexander Kuzmenko 8 سال پیش
والد
کامیت
4a9d32a794
5فایلهای تغییر یافته به همراه28 افزوده شده و 4 حذف شده
  1. 2 0
      std/cs/_std/sys/FileSystem.hx
  2. 2 2
      std/php/_std/sys/FileSystem.hx
  3. 2 2
      std/php7/_std/sys/FileSystem.hx
  4. 1 0
      tests/RunCi.hx
  5. 21 0
      tests/unit/src/unit/issues/Issue5742.hx

+ 2 - 0
std/cs/_std/sys/FileSystem.hx

@@ -103,11 +103,13 @@ class FileSystem {
 
 	public static function deleteFile( path : String ) : Void
 	{
+		if (!File.Exists(path)) throw "Path '" + path + "' doesn't exist";
 		File.Delete(path);
 	}
 
 	public static function deleteDirectory( path : String ) : Void
 	{
+		if (!Directory.Exists(path)) throw "Path '" + path + "' doesn't exist";
 		Directory.Delete(path);
 	}
 

+ 2 - 2
std/php/_std/sys/FileSystem.hx

@@ -96,11 +96,11 @@ class FileSystem {
 	}
 
 	public static inline function deleteFile( path : String ) : Void {
-		untyped __call__("@unlink", path);
+		untyped __call__("unlink", path);
 	}
 
 	public static inline function deleteDirectory( path : String ) : Void {
-		untyped __call__("@rmdir", path);
+		untyped __call__("rmdir", path);
 	}
 
 	public static function readDirectory( path : String ) : Array<String> {

+ 2 - 2
std/php7/_std/sys/FileSystem.hx

@@ -90,11 +90,11 @@ class FileSystem {
 	}
 
 	public static inline function deleteFile( path : String ) : Void {
-		Syntax.suppress(Global.unlink(path));
+		Global.unlink(path);
 	}
 
 	public static inline function deleteDirectory( path : String ) : Void {
-		Syntax.suppress(Global.rmdir(path));
+		Global.rmdir(path);
 	}
 
 	public static function readDirectory( path : String ) : Array<String> {

+ 1 - 0
tests/RunCi.hx

@@ -491,6 +491,7 @@ class RunCi {
 			runCommand("lua", ["-v"]);
 		}
 		runCommand("pip", ["install", "--user", "cpp-coveralls"]);
+		runCommand("luarocks", ["install", "luafilesystem", "1.6.3-2", "--server=https://luarocks.org/dev"]);
 		runCommand("luarocks", ["install", "lrexlib-pcre", "2.7.2-1", "--server=https://luarocks.org/dev"]);
 		runCommand("luarocks", ["install", "luautf8", "--server=https://luarocks.org/dev"]);
 

+ 21 - 0
tests/unit/src/unit/issues/Issue5742.hx

@@ -0,0 +1,21 @@
+package unit.issues;
+
+class Issue5742 extends Test {
+#if sys
+	function test(){
+		try {
+            sys.FileSystem.deleteFile('nonexistent.file');
+            t(false);
+        } catch(e:Dynamic) {
+            t(true);
+        }
+
+        try {
+            sys.FileSystem.deleteDirectory('nonexistent.directory');
+            t(false);
+        } catch(e:Dynamic) {
+            t(true);
+        }
+	}
+#end
+}