feat: support alternative git host with different archive structure

Some git hosting services name the directory inside their tarball
archive differently. For example codeberg, unlike github, does not add
the revision suffix to the direcotry in the tarball.
This commit is contained in:
madmaxieee 2025-09-14 21:24:34 +08:00
parent 7aa24acae3
commit 81d5366fb7

View file

@ -261,7 +261,27 @@ local function do_download(logger, url, project_name, cache_dir, revision, outpu
do -- Move tmp dir to output dir
local dir_rev = revision:find('^v%d') and revision:sub(2) or revision
local repo_project_name = url:match('[^/]-$')
local extracted = fs.joinpath(tmp, repo_project_name .. '-' .. dir_rev)
---@type string?
local extracted = nil
local candidates = {
fs.joinpath(tmp, repo_project_name .. '-' .. dir_rev),
fs.joinpath(tmp, repo_project_name),
}
for i, path in ipairs(candidates) do
if uv.fs_lstat(path) then
extracted = path
break
elseif i < #candidates then
logger:debug('Could not find extracted dir %s, trying %s...', path, candidates[i + 1])
end
end
if not extracted then
return logger:error('Could not find extracted dir')
end
logger:debug('Moving %s to %s/...', extracted, output_dir)
local err = uv_rename(extracted, output_dir)
a.schedule()