diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2020-02-05 15:18:14 +0100 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2020-02-05 16:48:21 +0100 |
commit | 201ac63c7692355b07b83034c1813c000ec70e84 (patch) | |
tree | e921ad9933609075768f2b97e6935c62ca39a254 | |
parent | 7c70a3208dcab7a9e568ede2a30b870ce0d96a20 (diff) | |
download | luarocks-201ac63c7692355b07b83034c1813c000ec70e84.tar.gz luarocks-201ac63c7692355b07b83034c1813c000ec70e84.tar.bz2 luarocks-201ac63c7692355b07b83034c1813c000ec70e84.zip |
fs.lua: fix error message when source file is missing
Fixes #1147.
-rw-r--r-- | spec/fs_spec.lua | 4 | ||||
-rw-r--r-- | src/luarocks/fs/lua.lua | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua index 5d8926c4..16295869 100644 --- a/spec/fs_spec.lua +++ b/spec/fs_spec.lua | |||
@@ -894,7 +894,9 @@ describe("Luarocks fs test #unit", function() | |||
894 | it("returns false and does nothing if the source file does not exist", function() | 894 | it("returns false and does nothing if the source file does not exist", function() |
895 | srcfile = get_tmp_path() | 895 | srcfile = get_tmp_path() |
896 | dstfile = get_tmp_path() | 896 | dstfile = get_tmp_path() |
897 | assert.falsy(fs.copy(srcfile, dstfile, nil)) | 897 | local ok, err = fs.copy(srcfile, dstfile, nil) |
898 | assert.falsy(ok) | ||
899 | assert.not_match("are the same file", err) | ||
898 | assert.falsy(exists_file(dstfile)) | 900 | assert.falsy(exists_file(dstfile)) |
899 | end) | 901 | end) |
900 | 902 | ||
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 6028a925..c5cebd2f 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -380,6 +380,20 @@ function fs_lua.remove_dir_tree_if_empty(d) | |||
380 | end | 380 | end |
381 | end | 381 | end |
382 | 382 | ||
383 | local function are_the_same_file(f1, f2) | ||
384 | if f1 == f2 then | ||
385 | return true | ||
386 | end | ||
387 | if cfg.is_platform("unix") then | ||
388 | local i1 = lfs.attributes(f1, "ino") | ||
389 | local i2 = lfs.attributes(f2, "ino") | ||
390 | if i1 ~= nil and i1 == i2 then | ||
391 | return true | ||
392 | end | ||
393 | end | ||
394 | return false | ||
395 | end | ||
396 | |||
383 | --- Copy a file. | 397 | --- Copy a file. |
384 | -- @param src string: Pathname of source | 398 | -- @param src string: Pathname of source |
385 | -- @param dest string: Pathname of destination | 399 | -- @param dest string: Pathname of destination |
@@ -395,7 +409,7 @@ function fs_lua.copy(src, dest, perms) | |||
395 | if destmode == "directory" then | 409 | if destmode == "directory" then |
396 | dest = dir.path(dest, dir.base_name(src)) | 410 | dest = dir.path(dest, dir.base_name(src)) |
397 | end | 411 | end |
398 | if src == dest or (cfg.is_platform("unix") and lfs.attributes(src, "ino") == lfs.attributes(dest, "ino")) then | 412 | if are_the_same_file(src, dest) then |
399 | return nil, "The source and destination are the same files" | 413 | return nil, "The source and destination are the same files" |
400 | end | 414 | end |
401 | local src_h, err = io.open(src, "rb") | 415 | local src_h, err = io.open(src, "rb") |