diff options
author | George Roman <george.roman.99@gmail.com> | 2018-04-19 18:42:01 +0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-04-24 17:15:35 -0300 |
commit | bcb010c10a795f565271cedb46af6aadba429205 (patch) | |
tree | df5704dbd995aee6242b9a43602523480f4d869a /src | |
parent | 315773caf4ee32c440df27d2339ad0f00460e8c5 (diff) | |
download | luarocks-bcb010c10a795f565271cedb46af6aadba429205.tar.gz luarocks-bcb010c10a795f565271cedb46af6aadba429205.tar.bz2 luarocks-bcb010c10a795f565271cedb46af6aadba429205.zip |
Make copy_contents have the same behaviour on Windows and on Unix
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/fs/lua.lua | 21 | ||||
-rw-r--r-- | src/luarocks/fs/win32/tools.lua | 5 |
2 files changed, 18 insertions, 8 deletions
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 38a37f0a..dfb6de41 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -323,6 +323,9 @@ local function recursive_copy(src, dest, perms) | |||
323 | local subdir = dir.path(dest, dir.base_name(src)) | 323 | local subdir = dir.path(dest, dir.base_name(src)) |
324 | local ok, err = fs.make_dir(subdir) | 324 | local ok, err = fs.make_dir(subdir) |
325 | if not ok then return nil, err end | 325 | if not ok then return nil, err end |
326 | if pcall(lfs.dir, src) == false then | ||
327 | return false | ||
328 | end | ||
326 | for file in lfs.dir(src) do | 329 | for file in lfs.dir(src) do |
327 | if file ~= "." and file ~= ".." then | 330 | if file ~= "." and file ~= ".." then |
328 | local ok = recursive_copy(dir.path(src, file), subdir, perms) | 331 | local ok = recursive_copy(dir.path(src, file), subdir, perms) |
@@ -336,15 +339,19 @@ end | |||
336 | --- Recursively copy the contents of a directory. | 339 | --- Recursively copy the contents of a directory. |
337 | -- @param src string: Pathname of source | 340 | -- @param src string: Pathname of source |
338 | -- @param dest string: Pathname of destination | 341 | -- @param dest string: Pathname of destination |
339 | -- @param perms string or nil: Optional permissions. | 342 | -- @param perms string or nil: Optional permissions. |
340 | -- @return boolean or (boolean, string): true on success, false on failure, | 343 | -- @return boolean or (boolean, string): true on success, false on failure, |
341 | -- plus an error message. | 344 | -- plus an error message. |
342 | function fs_lua.copy_contents(src, dest, perms) | 345 | function fs_lua.copy_contents(src, dest, perms) |
343 | assert(src and dest) | 346 | assert(src and dest) |
344 | src = dir.normalize(src) | 347 | src = dir.normalize(src) |
345 | dest = dir.normalize(dest) | 348 | dest = dir.normalize(dest) |
346 | assert(lfs.attributes(src, "mode") == "directory") | 349 | if not fs.is_dir(src) then |
347 | 350 | return false, src .. " is not a directory" | |
351 | end | ||
352 | if pcall(lfs.dir, src) == false then | ||
353 | return false, "Permission denied" | ||
354 | end | ||
348 | for file in lfs.dir(src) do | 355 | for file in lfs.dir(src) do |
349 | if file ~= "." and file ~= ".." then | 356 | if file ~= "." and file ~= ".." then |
350 | local ok = recursive_copy(dir.path(src, file), dest, perms) | 357 | local ok = recursive_copy(dir.path(src, file), dest, perms) |
@@ -539,14 +546,14 @@ local redirect_protocols = { | |||
539 | 546 | ||
540 | local function request(url, method, http, loop_control) | 547 | local function request(url, method, http, loop_control) |
541 | local result = {} | 548 | local result = {} |
542 | 549 | ||
543 | local proxy = cfg.http_proxy | 550 | local proxy = cfg.http_proxy |
544 | if type(proxy) ~= "string" then proxy = nil end | 551 | if type(proxy) ~= "string" then proxy = nil end |
545 | -- LuaSocket's http.request crashes when given URLs missing the scheme part. | 552 | -- LuaSocket's http.request crashes when given URLs missing the scheme part. |
546 | if proxy and not proxy:find("://") then | 553 | if proxy and not proxy:find("://") then |
547 | proxy = "http://" .. proxy | 554 | proxy = "http://" .. proxy |
548 | end | 555 | end |
549 | 556 | ||
550 | if cfg.show_downloads then | 557 | if cfg.show_downloads then |
551 | io.write(method.." "..url.." ...\n") | 558 | io.write(method.." "..url.." ...\n") |
552 | end | 559 | end |
@@ -608,7 +615,7 @@ end | |||
608 | -- @param http table: The library to use (http from LuaSocket or LuaSec) | 615 | -- @param http table: The library to use (http from LuaSocket or LuaSec) |
609 | -- @param cache boolean: Whether to use a `.timestamp` file to check | 616 | -- @param cache boolean: Whether to use a `.timestamp` file to check |
610 | -- via the HTTP Last-Modified header if the full download is needed. | 617 | -- via the HTTP Last-Modified header if the full download is needed. |
611 | -- @return (boolean | (nil, string, string?)): True if successful, or | 618 | -- @return (boolean | (nil, string, string?)): True if successful, or |
612 | -- nil, error message and optionally HTTPS error in case of errors. | 619 | -- nil, error message and optionally HTTPS error in case of errors. |
613 | local function http_request(url, filename, http, cache) | 620 | local function http_request(url, filename, http, cache) |
614 | if cache then | 621 | if cache then |
@@ -899,7 +906,7 @@ function fs_lua.is_lua(filename) | |||
899 | local lua = fs.Q(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)) -- get lua interpreter configured | 906 | local lua = fs.Q(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)) -- get lua interpreter configured |
900 | -- execute on configured interpreter, might not be the same as the interpreter LR is run on | 907 | -- execute on configured interpreter, might not be the same as the interpreter LR is run on |
901 | local result = fs.execute_string(lua..[[ -e "if loadfile(']]..filename..[[') then os.exit() else os.exit(1) end"]]) | 908 | local result = fs.execute_string(lua..[[ -e "if loadfile(']]..filename..[[') then os.exit() else os.exit(1) end"]]) |
902 | return (result == true) | 909 | return (result == true) |
903 | end | 910 | end |
904 | 911 | ||
905 | return fs_lua | 912 | return fs_lua |
diff --git a/src/luarocks/fs/win32/tools.lua b/src/luarocks/fs/win32/tools.lua index 7929fdec..b59d9391 100644 --- a/src/luarocks/fs/win32/tools.lua +++ b/src/luarocks/fs/win32/tools.lua | |||
@@ -79,7 +79,10 @@ end | |||
79 | -- plus an error message. | 79 | -- plus an error message. |
80 | function tools.copy_contents(src, dest) | 80 | function tools.copy_contents(src, dest) |
81 | assert(src and dest) | 81 | assert(src and dest) |
82 | if fs.execute_quiet(fs.Q(vars.CP), "-dR", src.."\\*.*", dest) then | 82 | if not fs.is_dir(src) then |
83 | return false, src .. " is not a directory" | ||
84 | end | ||
85 | if fs.make_dir(dest) and fs.execute_quiet(fs.Q(vars.CP), "-dR", src.."\\*.*", dest) then | ||
83 | return true | 86 | return true |
84 | else | 87 | else |
85 | return false, "Failed copying "..src.." to "..dest | 88 | return false, "Failed copying "..src.." to "..dest |