diff options
Diffstat (limited to 'xmake/core/base/os.lua')
| -rw-r--r-- | xmake/core/base/os.lua | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 271e5546d..b67a497d1 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -67,8 +67,9 @@ function os._cp(src, dst, rootdir, opt) end end - -- is file? - if os.isfile(src) or os.islink(src) then + -- is file or link? + local symlink = opt and opt.symlink + if os.isfile(src) or (symlink and os.islink(src)) then -- the destination is directory? append the filename if os.isdir(dst) or path.islastsep(dst) then @@ -79,16 +80,14 @@ function os._cp(src, dst, rootdir, opt) end end - -- link file if reserve symlink - if opt and opt.symlink and os.islink(src) then - local reallink = os.readlink(src) - if not os.link(reallink, dst) then - return false, string.format("cannot link %s(%s) to %s, %s", src, reallink, dst, os.strerror()) - end - else - -- copy file - if not os.cpfile(src, dst) then - return false, string.format("cannot copy file %s to %s, %s", src, dst, os.strerror()) + -- copy or link file + if not os.cpfile(src, dst, symlink) then + local errors = os.strerror() + if symlink and os.islink(src) then + local reallink = os.readlink(src) + return false, string.format("cannot link %s(%s) to %s, %s", src, reallink, dst, errors) + else + return false, string.format("cannot copy file %s to %s, %s", src, dst, errors) end end -- is directory? @@ -104,7 +103,7 @@ function os._cp(src, dst, rootdir, opt) end -- copy directory - if not os.cpdir(src, dst) then + if not os.cpdir(src, dst, symlink) then return false, string.format("cannot copy directory %s to %s, %s", src, dst, os.strerror()) end |
