From 44d9b7cd8ef84a84bd8d898dddc419c385e02daf Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 31 Aug 2022 22:39:10 +0800 Subject: improve os.cpfile --- core/src/tbox/tbox | 2 +- core/src/xmake/os/cpfile.c | 8 +++++++- xmake/core/base/os.lua | 19 +++++++++---------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index 4ab2cdf8d..6e4eab7e0 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit 4ab2cdf8dc94402d2277fd71ddc11eae913a30dc +Subproject commit 6e4eab7e07a2b535af6889de3f62cfec0384e99b 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? -- cgit v1.3.1