#29 Error when a package is obsoleted twice
Merged 3 years ago by churchyard. Opened 3 years ago by churchyard.
rpms/ churchyard/fedora-obsolete-packages no_duplicates  into  master

file modified
+34 -7
@@ -51,6 +51,10 @@ 

  %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 @@ 

          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 @@ 

          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 @@ 

          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')

This technically makes the %obsolete macro N^2, but still quite fast.

Heh, this Lua code works on my Fedora 32 machine, but not on rawhide :(

error: lua script failed: [string "<lua>"]:25: attempt to call a nil value (global 'unpack')

rebased onto 3ca9663b0432a8cf7bb66d3a815bb453950338b7

3 years ago

Updated from unpack to table.unpack.

rebased onto 517e481

3 years ago

Merging. It can be reverted if there is some outcry later.

Pull-Request has been merged by churchyard

3 years ago