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 | |
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
-rw-r--r-- | spec/fs_spec.lua | 17 | ||||
-rw-r--r-- | src/luarocks/fs/lua.lua | 21 | ||||
-rw-r--r-- | src/luarocks/fs/win32/tools.lua | 5 |
3 files changed, 21 insertions, 22 deletions
diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua index b36fded3..a74980f3 100644 --- a/spec/fs_spec.lua +++ b/spec/fs_spec.lua | |||
@@ -564,9 +564,6 @@ describe("Luarocks fs test #whitebox #w_fs", function() | |||
564 | fd:close() | 564 | fd:close() |
565 | dstdir = os.tmpname() | 565 | dstdir = os.tmpname() |
566 | os.remove(dstdir) | 566 | os.remove(dstdir) |
567 | if is_win then | ||
568 | lfs.mkdir(dstdir) | ||
569 | end | ||
570 | end | 567 | end |
571 | 568 | ||
572 | it("returns true and copies the contents (with their permissions) of the source dir to the destination dir", function() | 569 | it("returns true and copies the contents (with their permissions) of the source dir to the destination dir", function() |
@@ -604,11 +601,7 @@ describe("Luarocks fs test #whitebox #w_fs", function() | |||
604 | os.remove(srcdir) | 601 | os.remove(srcdir) |
605 | dstdir = os.tmpname() | 602 | dstdir = os.tmpname() |
606 | os.remove(dstdir) | 603 | os.remove(dstdir) |
607 | if is_win then | 604 | assert.falsy(fs.copy_contents(srcdir, dstdir, nil)) |
608 | fs.copy_contents(srcdir, dstdir, nil) | ||
609 | else | ||
610 | assert.falsy(pcall(fs.copy_contents, srcdir, dstdir, nil)) | ||
611 | end | ||
612 | assert.falsy(exists_file(dstdir)) | 605 | assert.falsy(exists_file(dstdir)) |
613 | end) | 606 | end) |
614 | 607 | ||
@@ -619,18 +612,14 @@ describe("Luarocks fs test #whitebox #w_fs", function() | |||
619 | fd:close() | 612 | fd:close() |
620 | dstdir = os.tmpname() | 613 | dstdir = os.tmpname() |
621 | os.remove(dstdir) | 614 | os.remove(dstdir) |
622 | if is_win then | 615 | assert.falsy(fs.copy_contents(srcdir, dstdir, nil)) |
623 | fs.copy_contents(srcdir, dstdir, nil) | ||
624 | else | ||
625 | assert.falsy(pcall(fs.copy_contents, srcdir, dstdir, nil)) | ||
626 | end | ||
627 | assert.falsy(exists_file(dstdir)) | 616 | assert.falsy(exists_file(dstdir)) |
628 | end) | 617 | end) |
629 | 618 | ||
630 | it("returns false and does nothing if the source dir doesn't have the proper permissions #unix", function() | 619 | it("returns false and does nothing if the source dir doesn't have the proper permissions #unix", function() |
631 | create_dir_tree() | 620 | create_dir_tree() |
632 | assert(fs.chmod(srcdir, "333")) | 621 | assert(fs.chmod(srcdir, "333")) |
633 | assert.falsy(pcall(fs.copy_contents, srcdir, dstdir, nil)) | 622 | assert.falsy(fs.copy_contents(srcdir, dstdir, nil)) |
634 | assert.falsy(exists_file(dstdir)) | 623 | assert.falsy(exists_file(dstdir)) |
635 | end) | 624 | end) |
636 | end) | 625 | end) |
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 |