copr-be: don't redirect files in the srpm-builds directory

And generally have an easy control on chroot level

See https://github.com/fedora-copr/copr/issues/3504
This commit is contained in:
Jakub Kadlcik 2025-02-04 12:39:00 +01:00 committed by praiskup
parent 7880b13991
commit ee05a46013

View file

@ -19,17 +19,26 @@ function line_in_file(searched, file)
end end
function uri_to_fullname(uri) function string_split(str, separator)
-- Take an URI which can look like this -- Split string into an array of strings.
-- /results/@copr/copr-dev/.../copr-cli-1.112-1.fc41.noarch.rpm -- The separator must be a single character
-- and parse only the project fullname from it, e.g. @copr/copr-dev local i = 1
local first = string.find(uri, "/", 2) local results = {}
local mid = string.find(uri, "/", first + 1) while true do
local last = string.find(uri, ":") local j = string.find(str, separator, i)
if not last then if j then
last = string.find(uri, "/", mid + 1) -- The `j` is an index of the separator and we want only the word before
-- the separator
j = j - 1
local value = string.sub(str, i, j)
table.insert(results, value)
-- Start from where we ended but skip the separator
i = j + 2
else
break
end end
return string.sub(uri, first + 1, last - 1) end
return results
end end
@ -47,8 +56,30 @@ function pulp_url(copr_path)
end end
local uri = lighty.env["uri.path"] function main()
local project = uri_to_fullname(uri) local uri = lighty.env["uri.path"]
if line_in_file(project, file_with_redirects) then local split = string_split(uri, "/")
if #(split) < 5 then
return
end
local owner, project, chroot = split[3], split[4], split[5]
if chroot == "srpm-builds" then
return
end
local fullname = owner .. "/" .. project
local colon = string.find(fullname, ":")
if colon then
fullname = string.sub(fullname, 0, colon - 1)
end
if not line_in_file(fullname, file_with_redirects) then
return
end
return redirect(pulp_url(uri)) return redirect(pulp_url(uri))
end end
return main()