From 517e48177d01f45069d00223cee08126ae3c7f4e Mon Sep 17 00:00:00 2001 From: Miro HronĨok Date: Jul 21 2020 11:44:32 +0000 Subject: Error when a package is obsoleted twice This technically makes the %obsolete macro N^2, but still quite fast. --- diff --git a/fedora-obsolete-packages.spec b/fedora-obsolete-packages.spec index 9021f80..ca0b31a 100644 --- a/fedora-obsolete-packages.spec +++ b/fedora-obsolete-packages.spec @@ -51,6 +51,10 @@ Source0: README %define obsolete() %{lua: local pkg = rpm.expand('%1') local ver = rpm.expand('%2') + local pkg_ + local ver_ + local i + local j if pkg == '%1' then rpm.expand('%{error:No package name provided to obsolete}') @@ -63,18 +67,31 @@ Source0: README rpm.expand('%{error:You must provide a version-release, not just a version.}') end - local o = pkg .. ' < ' .. ver - print('Obsoletes: ' .. o) + print('Obsoletes: ' .. pkg .. ' < ' .. ver) + + -- Check if the package wasn't already obsoleted + for i = 1,#obs do + for j = 1,#obs[i].list do + pkg_, ver_ = table.unpack(obs[i].list[j]) + if pkg == pkg_ then + rpm.expand('%{error:' .. pkg ..' obsoleted multiple times (' .. ver_ .. ' and ' .. ver ..').}') + end + end + end -- Append this obsolete to the last set of obsoletes in the list local list = obs[#obs].list - list[#list+1] = o + list[#list+1] = {pkg, ver} } # Don't use this macro! Only here because people keep doing this wrong. %define obsolete_wrong() %{lua: local pkg = rpm.expand('%1') local ver = rpm.expand('%2') + local pkg_ + local ver_ + local i + local j if pkg == '%1' then rpm.expand('%{error:No package name provided to obsolete}') @@ -83,12 +100,21 @@ Source0: README rpm.expand('%{error:No version provided to obsolete}') end - local o = pkg .. ' < ' .. ver - print('Obsoletes: ' .. o) + print('Obsoletes: ' .. pkg .. ' < ' .. ver) + + -- Check if the package wasn't already obsoleted + for i = 1,#obs do + for j = 1,#obs[i].list do + pkg_, ver_ = table.unpack(obs[i].list[j]) + if pkg == pkg_ then + rpm.expand('%{error:' .. pkg ..' obsoleted multiple times (' .. ver_ .. ' and ' .. ver ..').}') + end + end + end -- Append this obsolete to the last set of obsoletes in the list local list = obs[#obs].list - list[#list+1] = o + list[#list+1] = {pkg, ver} } @@ -104,7 +130,8 @@ Source0: README end for j = 1,#obs[i].list do - print(' ' .. obs[i].list[j] .. '\\n') + pkg, ver = table.unpack(obs[i].list[j]) + print(' ' .. pkg .. ' < ' .. ver .. '\\n') end if obs[i].ticket == nil then print(' (No ticket was provided!)\\n\\n')