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

Clearer extract errors #6124

Merged
merged 3 commits into from
Jan 28, 2025
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
19 changes: 15 additions & 4 deletions xmake/modules/private/action/require/impl/actions/download.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,20 @@ function _download(package, url, sourcedir, opt)
local sourcedir_tmp = sourcedir .. ".tmp"
os.rm(sourcedir_tmp)
local extension = archive.extension(packagefile)
local ok = try {function() archive.extract(packagefile, sourcedir_tmp, {excludes = opt.url_excludes}); return true end}
local errors
local ok = try {
function()
archive.extract(packagefile, sourcedir_tmp, {excludes = opt.url_excludes})
return true
end,
catch {
function (errs)
if errs then
errors = tostring(errs)
end
end
}
}
if ok then
-- move to source directory and we skip it to avoid long path issues on windows if only one root directory
os.rm(sourcedir)
Expand All @@ -241,7 +254,7 @@ function _download(package, url, sourcedir, opt)
-- create an empty source directory if do not extract package file
os.tryrm(sourcedir)
os.mkdir(sourcedir)
raise("cannot extract %s, maybe extractors(like unzip, ...) are not found!", packagefile)
raise(errors or string.format("cannot extract %s, maybe missing extractor or invalid package file!", packagefile))
else
-- if it is not archive file, we only need to create empty source directory and use package:originfile()
os.tryrm(sourcedir)
Expand Down Expand Up @@ -439,5 +452,3 @@ function main(package, opt)
os.cd(oldir)
return ok
end


Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,27 @@ function _download(package, resource_name, resource_url, resource_hash)
local resourcedir_tmp = resourcedir .. ".tmp"
os.tryrm(resourcedir_tmp)
local extension = archive.extension(resource_file)
local ok = try {function() archive.extract(resource_file, resourcedir_tmp); return true end}
local errors
local ok = try {
function()
archive.extract(resource_file, resourcedir_tmp)
return true
end,
catch {
function (errs)
if errs then
errors = tostring(errs)
end
end
}
}
if ok then
os.tryrm(resourcedir)
os.mv(resourcedir_tmp, resourcedir)
elseif extension and extension ~= "" then
os.tryrm(resourcedir_tmp)
os.tryrm(resourcedir)
raise("cannot extract %s", resource_file)
raise(errors or string.format("cannot extract %s", resource_file))
else
-- if it is not archive file, we only need to create empty resource directory and use package:resourcefile(resource_name)
os.tryrm(resourcedir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,27 @@ function _patch(package, patchinfo)
local patchdir = patch_file .. ".dir"
local patchdir_tmp = patchdir .. ".tmp"
os.tryrm(patchdir_tmp)
local ok = try {function() archive.extract(patch_file, patchdir_tmp); return true end}
local errors
local ok = try {
function()
archive.extract(patch_file, patchdir_tmp)
return true
end,
catch {
function (errs)
if errs then
errors = tostring(errs)
end
end
}
}
if ok then
os.tryrm(patchdir)
os.mv(patchdir_tmp, patchdir)
else
os.tryrm(patchdir_tmp)
os.tryrm(patchdir)
raise("cannot extract %s", patch_file)
raise(errors or string.format("cannot extract %s", patch_file))
end

-- apply patch files
Expand Down
2 changes: 1 addition & 1 deletion xmake/modules/utils/archive/archive.lua
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ function _archive(archivefile, inputfiles, extension, archivers, opt)
return true
end
end
raise("cannot archive %s, %s!", path.filename(archivefile), errors or "archivers not found!")
raise("cannot archive %s, %s!", path.filename(archivefile), errors or "no archiver(like zip, ...) found")
end

-- only archive tar file
Expand Down
2 changes: 1 addition & 1 deletion xmake/modules/utils/archive/extract.lua
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ function _extract(archivefile, outputdir, extension, extractors, opt)
return true
end
end
raise("cannot extract %s, %s!", path.filename(archivefile), errors or "extractors not found!")
raise("cannot extract %s, %s!", path.filename(archivefile), errors or "no extractor(like unzip, ...) found")
end

-- extract file
Expand Down
Loading