diff options
| author | ruki <[email protected]> | 2022-08-31 12:51:20 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-08-31 12:51:20 +0800 |
| commit | cfb302ba06a479ffddcf28e8acf727bea5d638fa (patch) | |
| tree | 7191ddbb89c4812cf0b28f2e7aa5d3027363adad /xmake/core | |
| parent | 3e398cf349c1ff3b9e9ebfa92f9dff99dfa8a97f (diff) | |
| parent | 6046e78b4d3ba893ef99f3e821736830dca1e5c2 (diff) | |
Merge pull request #2745 from xmake-io/symlink
improve symlink
Diffstat (limited to 'xmake/core')
| -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 |
