Whole file

hirak99/yabsnap

The author described this change as Fixes a bug where keep_preinstall = 0 caused error on pacman. It counts as a record because the check below fails on the code as it stood at a5564b5cb and passes on cedd9aed2, with nothing else changed between the two runs.

Fix saved2023-11-15
Sharing licenceApache-2.0 · LICENSE
Change size+12 2

What the code was meant to do, written into the code itself as a save note

Fixes a bug where keep_preinstall = 0 caused error on pacman

The change

5858
5959 def _all_but_last_k(array: list[_GenericT], k: int) -> Iterator[_GenericT]:
6060 """All but at most k last elements."""
61+ # Edge cases -
62+ # k > len(array): Returns empty array.
63+ # k < 0: Error.
6164 if k < 0:
6265 raise ValueError(f"k = {k} < 0")
6366 yield from array[: len(array) - k]
111114 ]
112115
113116 if count > 0:
117+ # From previously existing snaps, leave count - 1 snaps (since we
118+ # will create one more).
119+ n_snaps_to_leave = count - 1
120+ # Create a new snap.
114121 snapshot = snap_holder.Snapshot(self._config.dest_prefix + self._now_str)
115122 snapshot.metadata.trigger = trigger
116123 if comment:
117124 snapshot.metadata.comment = comment
118125 snapshot.create_from(self._config.source)
119126 self.snaps_created = True
127+ else:
128+ # From existing snaps, delete all.
129+ n_snaps_to_leave = 0
120130
121- # Clean up old snaps; leave count-1 previous snaps (plus the one now created).
122- for expired in _all_but_last_k(previous_snaps, count - 1):
131+ # Clean up old snaps.
132+ for expired in _all_but_last_k(previous_snaps, n_snaps_to_leave):
123133 expired.delete()
124134 self.snaps_deleted = True
125135

The check that tells the two apart

failpass·src/code/snap_operator_test.py::SnapOperatorTest::test_pachook

Check file src/code/snap_operator_test.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before ita5564b5cb34a9b1299d349cde188a05925501962
Broken version dated2023-11-13
Modulecode.snap_operator
Units changedSnapOperator, _all_but_last_k
Fingerprint0002e4710169e1cb
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in hirak99/yabsnap