Whole file
hirak99/yabsnap
The author described this change as “fix(tests): some tests were not being run”. It counts as a record because the checks below fail on the code as it stood at ed0a9dd5b and pass on 1f5811fab, with nothing else changed between the two runs.
Projecthirak99/yabsnap
Fix saved2025-02-24
Sharing licenceApache-2.0 · LICENSE
Change size+10 −9
What the code was meant to do, written into the code itself as a save note
fix(tests): some tests were not being run
The change
| 14 | 14 | ||
| 15 | 15 | import dataclasses | |
| 16 | 16 | import datetime | |
| 17 | + | import functools | |
| 17 | 18 | import os | |
| 18 | 19 | ||
| 19 | 20 | from .. import global_flags | |
| 20 | 21 | ||
| 21 | - | from typing import Iterable, Optional | |
| 22 | + | from typing import Optional | |
| 22 | 23 | ||
| 23 | 24 | # This will be cleaned up if it exists by rollback script. | |
| 24 | 25 | _PACMAN_LOCK_FILE = "/var/lib/pacman/db.lck" | |
| ⋯ | |||
| 31 | 32 | subvol_name: str | |
| 32 | 33 | ||
| 33 | 34 | ||
| 34 | - | def _get_mount_attributes( | |
| 35 | - | mount_point: str, mtab_lines: Iterable[str] | |
| 36 | - | ) -> _MountAttributes: | |
| 35 | + | @functools.cache | |
| 36 | + | def _mtab_contents() -> list[str]: | |
| 37 | + | with open("/etc/mtab") as f: | |
| 38 | + | return f.readlines() | |
| 39 | + | ||
| 40 | + | ||
| 41 | + | def _get_mount_attributes_from_mtab(mount_point: str) -> _MountAttributes: | |
| 37 | 42 | # For a mount point, this denotes the longest path that was seen in /etc/mtab. | |
| 38 | 43 | # This is therefore the point where that directory is mounted. | |
| 39 | 44 | longest_match_to_mount_point = "" | |
| 40 | 45 | # Which line matches the mount point. | |
| 41 | 46 | matched_line: str = "" | |
| 42 | - | for this_line in mtab_lines: | |
| 47 | + | for this_line in _mtab_contents(): | |
| 43 | 48 | this_tokens = this_line.split() | |
| 44 | 49 | if mount_point.startswith(this_tokens[1]): | |
| 45 | 50 | if len(this_tokens[1]) > len(longest_match_to_mount_point): | |
| ⋯ | |||
| 65 | 70 | assert nested_subvol.startswith("/") | |
| 66 | 71 | subvol_name = nested_subvol | |
| 67 | 72 | return _MountAttributes(device=tokens[0], subvol_name=subvol_name) | |
| 68 | - | ||
| 69 | - | ||
| 70 | - | def _get_mount_attributes_from_mtab(mount_point: str) -> _MountAttributes: | |
| 71 | - | return _get_mount_attributes(mount_point, open("/etc/mtab")) | |
| 72 | 73 | ||
| 73 | 74 | ||
| 74 | 75 | def _get_now_str(): | |
The check that tells the two apart
fail→pass·src/code/mechanisms/rollback_btrfs_test.py::TestRollbacker::test_get_mount_attributes
fail→pass·src/code/mechanisms/rollback_btrfs_test.py::TestRollbacker::test_rollback_btrfs_for_two_snaps
Check file src/code/mechanisms/rollback_btrfs_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 ited0a9dd5b4e5566eb9b51765a1ad08b9b618da10
Broken version dated2025-02-18
Modulecode.mechanisms.rollback_btrfs
Units changed_get_mount_attributes_from_mtab
Fingerprintefed78a342a061fa
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.