Skip to content

Commit 1c95d28

Browse files
authored
Merge pull request #6124 from Shiffted/extract_error
Clearer extract errors
2 parents 5616213 + c12f029 commit 1c95d28

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

xmake/modules/private/action/require/impl/actions/download.lua

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,20 @@ function _download(package, url, sourcedir, opt)
220220
local sourcedir_tmp = sourcedir .. ".tmp"
221221
os.rm(sourcedir_tmp)
222222
local extension = archive.extension(packagefile)
223-
local ok = try {function() archive.extract(packagefile, sourcedir_tmp, {excludes = opt.url_excludes}); return true end}
223+
local errors
224+
local ok = try {
225+
function()
226+
archive.extract(packagefile, sourcedir_tmp, {excludes = opt.url_excludes})
227+
return true
228+
end,
229+
catch {
230+
function (errs)
231+
if errs then
232+
errors = tostring(errs)
233+
end
234+
end
235+
}
236+
}
224237
if ok then
225238
-- move to source directory and we skip it to avoid long path issues on windows if only one root directory
226239
os.rm(sourcedir)
@@ -241,7 +254,7 @@ function _download(package, url, sourcedir, opt)
241254
-- create an empty source directory if do not extract package file
242255
os.tryrm(sourcedir)
243256
os.mkdir(sourcedir)
244-
raise("cannot extract %s, maybe extractors(like unzip, ...) are not found!", packagefile)
257+
raise(errors or string.format("cannot extract %s, maybe missing extractor or invalid package file!", packagefile))
245258
else
246259
-- if it is not archive file, we only need to create empty source directory and use package:originfile()
247260
os.tryrm(sourcedir)
@@ -439,5 +452,3 @@ function main(package, opt)
439452
os.cd(oldir)
440453
return ok
441454
end
442-
443-

xmake/modules/private/action/require/impl/actions/download_resources.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,27 @@ function _download(package, resource_name, resource_url, resource_hash)
135135
local resourcedir_tmp = resourcedir .. ".tmp"
136136
os.tryrm(resourcedir_tmp)
137137
local extension = archive.extension(resource_file)
138-
local ok = try {function() archive.extract(resource_file, resourcedir_tmp); return true end}
138+
local errors
139+
local ok = try {
140+
function()
141+
archive.extract(resource_file, resourcedir_tmp)
142+
return true
143+
end,
144+
catch {
145+
function (errs)
146+
if errs then
147+
errors = tostring(errs)
148+
end
149+
end
150+
}
151+
}
139152
if ok then
140153
os.tryrm(resourcedir)
141154
os.mv(resourcedir_tmp, resourcedir)
142155
elseif extension and extension ~= "" then
143156
os.tryrm(resourcedir_tmp)
144157
os.tryrm(resourcedir)
145-
raise("cannot extract %s", resource_file)
158+
raise(errors or string.format("cannot extract %s", resource_file))
146159
else
147160
-- if it is not archive file, we only need to create empty resource directory and use package:resourcefile(resource_name)
148161
os.tryrm(resourcedir)

xmake/modules/private/action/require/impl/actions/patch_sources.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,27 @@ function _patch(package, patchinfo)
107107
local patchdir = patch_file .. ".dir"
108108
local patchdir_tmp = patchdir .. ".tmp"
109109
os.tryrm(patchdir_tmp)
110-
local ok = try {function() archive.extract(patch_file, patchdir_tmp); return true end}
110+
local errors
111+
local ok = try {
112+
function()
113+
archive.extract(patch_file, patchdir_tmp)
114+
return true
115+
end,
116+
catch {
117+
function (errs)
118+
if errs then
119+
errors = tostring(errs)
120+
end
121+
end
122+
}
123+
}
111124
if ok then
112125
os.tryrm(patchdir)
113126
os.mv(patchdir_tmp, patchdir)
114127
else
115128
os.tryrm(patchdir_tmp)
116129
os.tryrm(patchdir)
117-
raise("cannot extract %s", patch_file)
130+
raise(errors or string.format("cannot extract %s", patch_file))
118131
end
119132

120133
-- apply patch files

xmake/modules/utils/archive/archive.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ function _archive(archivefile, inputfiles, extension, archivers, opt)
306306
return true
307307
end
308308
end
309-
raise("cannot archive %s, %s!", path.filename(archivefile), errors or "archivers not found!")
309+
raise("cannot archive %s, %s!", path.filename(archivefile), errors or "no archiver(like zip, ...) found")
310310
end
311311

312312
-- only archive tar file

xmake/modules/utils/archive/extract.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ function _extract(archivefile, outputdir, extension, extractors, opt)
446446
return true
447447
end
448448
end
449-
raise("cannot extract %s, %s!", path.filename(archivefile), errors or "extractors not found!")
449+
raise("cannot extract %s, %s!", path.filename(archivefile), errors or "no extractor(like unzip, ...) found")
450450
end
451451

452452
-- extract file

0 commit comments

Comments
 (0)