Ver código fonte

[lua] escape path in file copy

Justin Donaldson 8 anos atrás
pai
commit
9383b8e0a5
2 arquivos alterados com 6 adições e 2 exclusões
  1. 1 0
      std/lua/_std/Array.hx
  2. 5 2
      std/lua/_std/sys/io/File.hx

+ 1 - 0
std/lua/_std/Array.hx

@@ -106,6 +106,7 @@ class Array<T> {
 			i += 1;
 		}
 	}
+
 	public function splice( pos : Int, len : Int ) : Array<T> {
 		if (len < 0 || pos > length) return [];
 		else if (pos < 0) pos = length -(-pos % length);

+ 5 - 2
std/lua/_std/sys/io/File.hx

@@ -24,6 +24,7 @@ import lua.Lua;
 import lua.Io;
 import lua.Os;
 import lua.FileHandle;
+import lua.Boot;
 
 @:coreApi
 class File {
@@ -40,8 +41,10 @@ class File {
 	}
 
 	public static function copy( srcPath : String, dstPath : String ) : Void {
-		// TODO : escape paths
-		Os.execute('copy $srcPath $dstPath');
+		switch (Sys.systemName()) {
+			case "Windows" : Os.execute('copy ${StringTools.quoteWinArg(srcPath, true)} ${StringTools.quoteWinArg(dstPath,true)}');
+			default : Os.execute('copy ${StringTools.quoteUnixArg(srcPath)} ${StringTools.quoteUnixArg(dstPath)}');
+		};
 	}
 
 	public static function getBytes( path : String ) : haxe.io.Bytes {