summaryrefslogtreecommitdiff
path: root/xmake/core/base/os.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-08-21 00:46:07 +0800
committerruki <[email protected]>2021-08-21 00:46:07 +0800
commita226ce07d85f3aab66b6dacf6f91e85f7296a490 (patch)
tree7aead5aa3cccab016e06175eddf040fb40b7de89 /xmake/core/base/os.lua
parentc95fdc3f443b3dee83708b42bc34383a47601e13 (diff)
improve to copy symlink for installation
Diffstat (limited to 'xmake/core/base/os.lua')
-rw-r--r--xmake/core/base/os.lua24
1 files changed, 16 insertions, 8 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index e9f403d92..ea913b977 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -49,7 +49,7 @@ os.SYSERR_NOT_PERM = 1
os.SYSERR_NOT_FILEDIR = 2
-- copy single file or directory
-function os._cp(src, dst, rootdir)
+function os._cp(src, dst, rootdir, opt)
-- check
assert(src and dst)
@@ -65,7 +65,7 @@ function os._cp(src, dst, rootdir)
end
-- is file?
- if os.isfile(src) then
+ if os.isfile(src) or os.islink(src) then
-- the destination is directory? append the filename
if os.isdir(dst) or path.islastsep(dst) then
@@ -76,9 +76,17 @@ function os._cp(src, dst, rootdir)
end
end
- -- copy file
- if not os.cpfile(src, dst) then
- return false, string.format("cannot copy file %s to %s, %s", src, dst, os.strerror())
+ -- 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())
+ end
end
-- is directory?
elseif os.isdir(src) then
@@ -386,7 +394,7 @@ function os.filedirs(pattern, callback)
end
-- copy files or directories and we can reserve the source directory structure
--- e.g. os.cp("src/**.h", "/tmp/", {rootdir = "src"})
+-- e.g. os.cp("src/**.h", "/tmp/", {rootdir = "src", symlink = true})
function os.cp(srcpath, dstpath, opt)
-- check arguments
@@ -405,10 +413,10 @@ function os.cp(srcpath, dstpath, opt)
-- copy files or directories
local srcpathes = os._match_wildcard_pathes(srcpath)
if type(srcpathes) == "string" then
- return os._cp(srcpathes, dstpath, rootdir)
+ return os._cp(srcpathes, dstpath, rootdir, opt)
else
for _, _srcpath in ipairs(srcpathes) do
- local ok, errors = os._cp(_srcpath, dstpath, rootdir)
+ local ok, errors = os._cp(_srcpath, dstpath, rootdir, opt)
if not ok then
return false, errors
end