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.
Projecthirak99/yabsnap
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
| 58 | 58 | ||
| 59 | 59 | def _all_but_last_k(array: list[_GenericT], k: int) -> Iterator[_GenericT]: | |
| 60 | 60 | """All but at most k last elements.""" | |
| 61 | + | # Edge cases - | |
| 62 | + | # k > len(array): Returns empty array. | |
| 63 | + | # k < 0: Error. | |
| 61 | 64 | if k < 0: | |
| 62 | 65 | raise ValueError(f"k = {k} < 0") | |
| 63 | 66 | yield from array[: len(array) - k] | |
| ⋯ | |||
| 111 | 114 | ] | |
| 112 | 115 | ||
| 113 | 116 | 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. | |
| 114 | 121 | snapshot = snap_holder.Snapshot(self._config.dest_prefix + self._now_str) | |
| 115 | 122 | snapshot.metadata.trigger = trigger | |
| 116 | 123 | if comment: | |
| 117 | 124 | snapshot.metadata.comment = comment | |
| 118 | 125 | snapshot.create_from(self._config.source) | |
| 119 | 126 | self.snaps_created = True | |
| 127 | + | else: | |
| 128 | + | # From existing snaps, delete all. | |
| 129 | + | n_snaps_to_leave = 0 | |
| 120 | 130 | ||
| 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): | |
| 123 | 133 | expired.delete() | |
| 124 | 134 | self.snaps_deleted = True | |
| 125 | 135 | ||
The check that tells the two apart
fail→pass·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.