Przeglądaj źródła

[lua] throw if failed to File.copy() (#8104)

* [lua] throw if failed to File.copy() (#8098)

* [lua] fix File.copy() for  lua 5.2

* try to delete destination path before File.copy

* fix conditional compilation syntax

* fix File.copy() for cases when `lua_ver` is not specified

* [lua] fix File.copy. This time for sure
Alexander Kuzmenko 6 lat temu
rodzic
commit
3ab7ab1334
1 zmienionych plików z 8 dodań i 1 usunięć
  1. 8 1
      std/lua/_std/sys/io/File.hx

+ 8 - 1
std/lua/_std/sys/io/File.hx

@@ -48,10 +48,17 @@ class File {
 	}
 
 	public static function copy( srcPath : String, dstPath : String ) : Void {
-		switch (Sys.systemName()) {
+		var result = switch (Sys.systemName()) {
 			case "Windows" : Os.execute('copy ${StringTools.quoteWinArg(srcPath, true)} ${StringTools.quoteWinArg(dstPath,true)}');
 			default : Os.execute('cp ${StringTools.quoteUnixArg(srcPath)} ${StringTools.quoteUnixArg(dstPath)}');
 		};
+		if(
+			#if (lua_ver >= 5.2) !result.success
+			#elseif (lua_ver < 5.2) result != 0
+			#else ((result:Dynamic) != true && (result:Dynamic) != 0) #end
+		) {
+			throw 'Failed to copy $srcPath to $dstPath';
+		}
 	}
 
 	public static function getBytes( path : String ) : haxe.io.Bytes {