Skip to content

Commit 27a68c7

Browse files
authored
Merge pull request #6835 from xmake-io/package
fix package extension
2 parents a97d95f + 95db372 commit 27a68c7

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ import("net.proxy")
3434
import("devel.git")
3535
import("utils.archive")
3636

37+
-- get url extension
38+
function _url_extension(url)
39+
local extension = archive.extension(url)
40+
if extension == "" then
41+
-- maybe non-archive file, e.g. .exe, .sh, ..
42+
local urlpath = url:split('?', {plain = true})[1]
43+
extension = path.extension(urlpath)
44+
end
45+
return extension
46+
end
47+
3748
-- checkout codes from git
3849
function _checkout(package, url, sourcedir, opt)
3950
opt = opt or {}
@@ -153,7 +164,7 @@ function _download(package, url, sourcedir, opt)
153164
if not packagefile then
154165
packagefile = url_filename(url)
155166
if not os.isfile(packagefile) then -- we need to be compatible with the old file names
156-
packagefile = package:name() .. "-" .. package:version_str() .. archive.extension(packagefile)
167+
packagefile = package:name() .. "-" .. package:version_str() .. _url_extension(packagefile)
157168
end
158169
end
159170

@@ -181,7 +192,7 @@ function _download(package, url, sourcedir, opt)
181192
os.cp(url, packagefile)
182193
else
183194
local localfile
184-
local searchnames = {package:name() .. "-" .. package:version_str() .. archive.extension(url),
195+
local searchnames = {package:name() .. "-" .. package:version_str() .. _url_extension(url),
185196
packagefile}
186197

187198
-- match github name mangling https://github.com/xmake-io/xmake/issues/1343
@@ -267,6 +278,7 @@ function _download(package, url, sourcedir, opt)
267278
raise(errors or string.format("cannot extract %s, maybe missing extractor or invalid package file!", packagefile))
268279
else
269280
-- if it is not archive file, we only need to create empty source directory and use package:originfile()
281+
-- e.g. .exe, .sh
270282
os.tryrm(sourcedir)
271283
os.mkdir(sourcedir)
272284
end
@@ -424,7 +436,7 @@ function main(package, opt)
424436
searchnames:insert(package:name() .. archive.extension(url_failed))
425437
searchnames:insert(path.basename(url_filename(url_failed)))
426438
else
427-
local extension = archive.extension(url_failed)
439+
local extension = _url_extension(url_failed)
428440
if extension then
429441
searchnames:insert(package:name() .. "-" .. package:version_str() .. extension)
430442
end

xmake/modules/utils/archive/extension.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
import("core.base.hashset")
2323

2424
-- get the archive extension
25-
function main(archivefile)
25+
function main(url)
26+
local urlpath = url:split('?', {plain = true})[1]
2627
local extension = ""
27-
local filename = path.filename(archivefile)
28+
local filename = path.filename(urlpath)
2829
local extensionset = hashset.from({
2930
".xmz", -- xmake compression format
3031
".zip", ".7z", ".gz", ".xz", ".zst", ".tgz",

0 commit comments

Comments
 (0)