kmod.attr: fix string.gsub patterns and return values
basename(): return one value, not two (principle of least confusion). strip_compress_sfx(): ditto strip_compress_sfx(): fix it, it had several problems: (a) incorrect escaping of . (period) ... masked by incorrect use of backslash (b) lua has no | "or" pattern Use simpler gsub patterns / replacements, presumably faster (did not measure). Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
This commit is contained in:
parent
5df3d6d58b
commit
e9cc0440fd
25
kmod.attr
25
kmod.attr
@ -1,10 +1,31 @@
|
||||
%__kmod_path ^/lib/modules/.*/(modules.builtin|.*\.ko|.*\.ko\.gz|.*\.ko\.bz2|.*\.ko\.xz|.*\.ko\.zst)$
|
||||
|
||||
# Notes on Lua:
|
||||
# The backslash in strings (like "\n" newline) needs to be doubled
|
||||
# because we are inside rpm macro. Single backslashes before most chars
|
||||
# disappear (removed by rpm's parser), so "\n" turns into just "n".
|
||||
# In string.gsub patterns, unlike regexps, backslash has no special meaning.
|
||||
# It can't escape . and such. (Use one-character set [.] to represent
|
||||
# literal period, or lua's percent escape: %.)
|
||||
# Pipe (|) has no special meaning too.
|
||||
|
||||
%__kmod_provides() %{lua:
|
||||
function basename(fn)
|
||||
return string.gsub(fn, "(.*/)(.*)", "%2")
|
||||
local b = string.gsub(fn, ".*/", "")
|
||||
-- the above adjusts gsub() result to 1 value
|
||||
-- "return f()" construct would return _all_ values, two in case of gsub()
|
||||
return b
|
||||
end
|
||||
function strip_compress_sfx(fn)
|
||||
return string.gsub(fn, "(.*)(\.gz|\.bz2|\.xz|\.zst)?$", "%1")
|
||||
local cnt
|
||||
fn, cnt = string.gsub(fn, "%.gz$", "")
|
||||
if cnt == 1 then return fn; end
|
||||
fn, cnt = string.gsub(fn, "%.bz2$", "")
|
||||
if cnt == 1 then return fn; end
|
||||
fn, cnt = string.gsub(fn, "%.xz$", "")
|
||||
if cnt == 1 then return fn; end
|
||||
fn, cnt = string.gsub(fn, "%.zst$", "")
|
||||
return fn
|
||||
end
|
||||
function printdep(mod)
|
||||
print("kmod("..mod..") ")
|
||||
|
Loading…
Reference in New Issue
Block a user