summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-08-31 22:39:10 +0800
committerruki <[email protected]>2022-08-31 22:39:10 +0800
commit44d9b7cd8ef84a84bd8d898dddc419c385e02daf (patch)
tree045b46d2029d30f092494887f8857bccc72cd5a2
parentdf6efbec2309e41c67e6ffdc8386a600ca04c21d (diff)
improve os.cpfile
m---------core/src/tbox/tbox0
-rw-r--r--core/src/xmake/os/cpfile.c8
-rw-r--r--xmake/core/base/os.lua19
3 files changed, 16 insertions, 11 deletions
diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox
-Subproject 4ab2cdf8dc94402d2277fd71ddc11eae913a30d
+Subproject 6e4eab7e07a2b535af6889de3f62cfec0384e99
diff --git a/core/src/xmake/os/cpfile.c b/core/src/xmake/os/cpfile.c
index 4490172da..153f51de0 100644
--- a/core/src/xmake/os/cpfile.c
+++ b/core/src/xmake/os/cpfile.c
@@ -43,7 +43,13 @@ tb_int_t xm_os_cpfile(lua_State* lua)
tb_char_t const* dst = luaL_checkstring(lua, 2);
tb_check_return_val(src && dst, 0);
+ // init copy flags
+ tb_size_t flags = TB_FILE_COPY_NONE;
+ tb_bool_t is_symlink = lua_toboolean(lua, 3);
+ if (is_symlink)
+ flags |= TB_FILE_COPY_LINK;
+
// do copy
- lua_pushboolean(lua, tb_file_copy(src, dst));
+ lua_pushboolean(lua, tb_file_copy(src, dst, flags));
return 1;
}
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 271e5546d..ad33699f4 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -79,16 +79,15 @@ 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
+ local symlink = opt and opt.symlink
+ 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?