From 32cabe08be37cbc98d02a81076cbe8fe2fadda9b Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 5 Sep 2024 00:57:17 +0800 Subject: add writeable for os.cp #5138 --- core/src/tbox/tbox | 2 +- core/src/xmake/os/cpfile.c | 4 ++++ xmake/actions/create/main.lua | 2 +- xmake/core/base/os.lua | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/tbox/tbox b/core/src/tbox/tbox index 57e57a327..e222f6166 160000 --- a/core/src/tbox/tbox +++ b/core/src/tbox/tbox @@ -1 +1 @@ -Subproject commit 57e57a3271ad925936b3fbf37877f9eceb49ee4e +Subproject commit e222f61667fdafb9189849d2970c01e13940b0b9 diff --git a/core/src/xmake/os/cpfile.c b/core/src/xmake/os/cpfile.c index 153f51de0..06184cf21 100644 --- a/core/src/xmake/os/cpfile.c +++ b/core/src/xmake/os/cpfile.c @@ -49,6 +49,10 @@ tb_int_t xm_os_cpfile(lua_State* lua) if (is_symlink) flags |= TB_FILE_COPY_LINK; + tb_bool_t is_writeable = lua_toboolean(lua, 4); + if (is_writeable) + flags |= TB_FILE_COPY_WRITEABLE; + // do copy lua_pushboolean(lua, tb_file_copy(src, dst, flags)); return 1; diff --git a/xmake/actions/create/main.lua b/xmake/actions/create/main.lua index 69aa52997..14a7dc0a6 100644 --- a/xmake/actions/create/main.lua +++ b/xmake/actions/create/main.lua @@ -98,7 +98,7 @@ function _create_project(language, templateid, targetname) local sourcedir = path.join(tempinst:scriptdir(), "project") if os.isdir(sourcedir) then for _, filedir in ipairs(os.filedirs(path.join(sourcedir, "*"))) do - os.cp(filedir, projectdir) + os.cp(filedir, projectdir, {writeable = true}) table.insert(filedirs, path.relative(filedir, sourcedir)) end os.cp(path.join(os.programdir(), "scripts", "gitignore"), path.join(projectdir, ".gitignore")) diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua index 2dba50509..6a1151e23 100644 --- a/xmake/core/base/os.lua +++ b/xmake/core/base/os.lua @@ -70,6 +70,7 @@ function os._cp(src, dst, rootdir, opt) -- is file or link? local symlink = opt.symlink + local writeable = opt.writeable if os.isfile(src) or (symlink and os.islink(src)) then -- the destination is directory? append the filename @@ -85,7 +86,7 @@ function os._cp(src, dst, rootdir, opt) if opt.force and os.isfile(dst) then os.rmfile(dst) end - if not os.cpfile(src, dst, symlink) then + if not os.cpfile(src, dst, symlink, writeable) then local errors = os.strerror() if symlink and os.islink(src) then local reallink = os.readlink(src) -- cgit v1.3.1