Skip to content

Commit e9df84a

Browse files
authored
Merge pull request #5570 from xmake-io/cpfile
Improve to copy file
2 parents a3f5028 + ee49350 commit e9df84a

File tree

7 files changed

+12
-6
lines changed

7 files changed

+12
-6
lines changed

core/src/xmake/os/cpfile.c

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ tb_int_t xm_os_cpfile(lua_State* lua)
4949
if (is_symlink)
5050
flags |= TB_FILE_COPY_LINK;
5151

52+
tb_bool_t is_writeable = lua_toboolean(lua, 4);
53+
if (is_writeable)
54+
flags |= TB_FILE_COPY_WRITEABLE;
55+
5256
// do copy
5357
lua_pushboolean(lua, tb_file_copy(src, dst, flags));
5458
return 1;

xmake/actions/create/main.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ function _create_project(language, templateid, targetname)
9898
local sourcedir = path.join(tempinst:scriptdir(), "project")
9999
if os.isdir(sourcedir) then
100100
for _, filedir in ipairs(os.filedirs(path.join(sourcedir, "*"))) do
101-
os.cp(filedir, projectdir)
101+
-- https://github.com/xmake-io/xmake/issues/5138#issuecomment-2329238617
102+
os.cp(filedir, projectdir, {writeable = true})
102103
table.insert(filedirs, path.relative(filedir, sourcedir))
103104
end
104105
os.cp(path.join(os.programdir(), "scripts", "gitignore"), path.join(projectdir, ".gitignore"))

xmake/core/base/os.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function os._cp(src, dst, rootdir, opt)
7070

7171
-- is file or link?
7272
local symlink = opt.symlink
73+
local writeable = opt.writeable
7374
if os.isfile(src) or (symlink and os.islink(src)) then
7475

7576
-- the destination is directory? append the filename
@@ -85,7 +86,7 @@ function os._cp(src, dst, rootdir, opt)
8586
if opt.force and os.isfile(dst) then
8687
os.rmfile(dst)
8788
end
88-
if not os.cpfile(src, dst, symlink) then
89+
if not os.cpfile(src, dst, symlink, writeable) then
8990
local errors = os.strerror()
9091
if symlink and os.islink(src) then
9192
local reallink = os.readlink(src)

xmake/plugins/pack/deb/main.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function _pack_deb(debuild, package)
191191
local debiandir = path.join(sourcedir, "debian")
192192
if not os.isdir(debiandir) then
193193
local debiandir_template = package:get("specfile") or path.join(os.programdir(), "scripts", "xpack", "deb", "debian")
194-
os.cp(debiandir_template, debiandir)
194+
os.cp(debiandir_template, debiandir, {writeable = true})
195195
end
196196

197197
-- replace variables in specfile

xmake/plugins/pack/runself/main.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ function _pack_runself(makeself, package)
111111
local specfile = path.join(package:buildir(), package:basename() .. ".lsm")
112112
if not os.isfile(specfile) then
113113
local specfile_template = package:get("specfile") or path.join(os.programdir(), "scripts", "xpack", "runself", "makeself.lsm")
114-
os.cp(specfile_template, specfile)
114+
os.cp(specfile_template, specfile, {writeable = true})
115115
end
116116

117117
-- replace variables in specfile

xmake/plugins/pack/srpm/main.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function _pack_srpm(rpmbuild, package)
205205
local specfile = path.join(package:buildir(), package:basename() .. ".spec")
206206
if not os.isfile(specfile) then
207207
local specfile_template = package:get("specfile") or path.join(os.programdir(), "scripts", "xpack", "srpm", "srpm.spec")
208-
os.cp(specfile_template, specfile)
208+
os.cp(specfile_template, specfile, {writeable = true})
209209
end
210210

211211
-- replace variables in specfile

0 commit comments

Comments
 (0)