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.

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

1414
1515 import dataclasses
1616 import datetime
17+import functools
1718 import os
1819
1920 from .. import global_flags
2021
21-from typing import Iterable, Optional
22+from typing import Optional
2223
2324 # This will be cleaned up if it exists by rollback script.
2425 _PACMAN_LOCK_FILE = "/var/lib/pacman/db.lck"
3132 subvol_name: str
3233
3334
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:
3742 # For a mount point, this denotes the longest path that was seen in /etc/mtab.
3843 # This is therefore the point where that directory is mounted.
3944 longest_match_to_mount_point = ""
4045 # Which line matches the mount point.
4146 matched_line: str = ""
42- for this_line in mtab_lines:
47+ for this_line in _mtab_contents():
4348 this_tokens = this_line.split()
4449 if mount_point.startswith(this_tokens[1]):
4550 if len(this_tokens[1]) > len(longest_match_to_mount_point):
6570 assert nested_subvol.startswith("/")
6671 subvol_name = nested_subvol
6772 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"))
7273
7374
7475 def _get_now_str():

The check that tells the two apart

failpass·src/code/mechanisms/rollback_btrfs_test.py::TestRollbacker::test_get_mount_attributes
failpass·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.

Other bugs found in hirak99/yabsnap