2026-10-27 01:21:04 +01:00
|
|
|
#!/usr/bin/env python3
|
2026-10-27 17:13:09 +01:00
|
|
|
"""Remove only this source version's inventory; never recurse directories."""
|
2026-10-27 01:21:04 +01:00
|
|
|
import argparse
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
import stat
|
2026-10-27 17:13:09 +01:00
|
|
|
from install_layout import arguments, inventory, layout, staged
|
2026-10-27 01:21:04 +01:00
|
|
|
|
|
|
|
|
|
2026-10-27 17:13:09 +01:00
|
|
|
def main():
|
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
|
|
|
arguments(parser)
|
|
|
|
|
parser.add_argument('--root', help='legacy alias for --prefix')
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
if args.root:
|
|
|
|
|
args.prefix = args.root
|
|
|
|
|
files = [staged(path, args.destdir) for path, _ in inventory(Path(__file__).resolve().parent.parent, layout(args))]
|
2026-10-27 01:21:04 +01:00
|
|
|
for path in files:
|
|
|
|
|
try:
|
|
|
|
|
mode = path.lstat().st_mode
|
|
|
|
|
except FileNotFoundError:
|
|
|
|
|
continue
|
|
|
|
|
if not (stat.S_ISREG(mode) or stat.S_ISLNK(mode)):
|
|
|
|
|
raise ValueError(f'Refusing non-file: {path}')
|
|
|
|
|
for path in files:
|
|
|
|
|
path.unlink(missing_ok=True)
|
2026-10-27 17:13:09 +01:00
|
|
|
# Only try the immediate owned directories, never walk up to / or DESTDIR.
|
|
|
|
|
parents = {p.parent for p in files}
|
2026-10-27 01:21:04 +01:00
|
|
|
for parent in sorted(parents, key=lambda p: len(p.parts), reverse=True):
|
|
|
|
|
try:
|
|
|
|
|
parent.rmdir()
|
2026-10-27 17:13:09 +01:00
|
|
|
except OSError:
|
|
|
|
|
pass
|
2026-10-27 01:21:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2026-10-27 17:13:09 +01:00
|
|
|
main()
|