Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve to copy file #5570

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/tbox/tbox
4 changes: 4 additions & 0 deletions core/src/xmake/os/cpfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion xmake/actions/create/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ 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)
-- https://github.com/xmake-io/xmake/issues/5138#issuecomment-2329238617
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"))
Expand Down
3 changes: 2 additions & 1 deletion xmake/core/base/os.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion xmake/plugins/pack/deb/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function _pack_deb(debuild, package)
local debiandir = path.join(sourcedir, "debian")
if not os.isdir(debiandir) then
local debiandir_template = package:get("specfile") or path.join(os.programdir(), "scripts", "xpack", "deb", "debian")
os.cp(debiandir_template, debiandir)
os.cp(debiandir_template, debiandir, {writeable = true})
end

-- replace variables in specfile
Expand Down
2 changes: 1 addition & 1 deletion xmake/plugins/pack/runself/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function _pack_runself(makeself, package)
local specfile = path.join(package:buildir(), package:basename() .. ".lsm")
if not os.isfile(specfile) then
local specfile_template = package:get("specfile") or path.join(os.programdir(), "scripts", "xpack", "runself", "makeself.lsm")
os.cp(specfile_template, specfile)
os.cp(specfile_template, specfile, {writeable = true})
end

-- replace variables in specfile
Expand Down
2 changes: 1 addition & 1 deletion xmake/plugins/pack/srpm/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function _pack_srpm(rpmbuild, package)
local specfile = path.join(package:buildir(), package:basename() .. ".spec")
if not os.isfile(specfile) then
local specfile_template = package:get("specfile") or path.join(os.programdir(), "scripts", "xpack", "srpm", "srpm.spec")
os.cp(specfile_template, specfile)
os.cp(specfile_template, specfile, {writeable = true})
end

-- replace variables in specfile
Expand Down
Loading