From: Daan De Meyer Date: Tue, 31 Jan 2023 18:37:28 +0000 (+0100) Subject: Remove btrfs subvolume deletion logic X-Git-Tag: v15~344^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc901f7e4365e86926b96f567cd7cca776dd8cd6;p=thirdparty%2Fmkosi.git Remove btrfs subvolume deletion logic Deleting btrfs subvolumes requires root. Given that we'll be moving to primarily unprivileged execution soon, let's drop the logic for deleting btrfs subvolumes. They're still deleted if the corresponding directory is removed, it's just slightly slower. --- diff --git a/mkosi/remove.py b/mkosi/remove.py index 29ed078d5..aa0d02413 100644 --- a/mkosi/remove.py +++ b/mkosi/remove.py @@ -1,34 +1,9 @@ # SPDX-License-Identifier: LGPL-2.1+ -import os import shutil -import subprocess from pathlib import Path from typing import Optional -from mkosi.backend import run - - -def btrfs_subvol_delete(path: Path) -> None: - # Extract the path of the subvolume relative to the filesystem - c = run(["btrfs", "subvol", "show", path], - stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True) - subvol_path = c.stdout.splitlines()[0] - # Make the subvolume RW again if it was set RO by btrfs_subvol_delete - run(["btrfs", "property", "set", path, "ro", "false"]) - # Recursively delete the direct children of the subvolume - c = run(["btrfs", "subvol", "list", "-o", path], - stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True) - for line in c.stdout.splitlines(): - if not line: - continue - child_subvol_path = line.split(" ", 8)[-1] - child_path = path / os.path.relpath(child_subvol_path, subvol_path) - btrfs_subvol_delete(child_path) - # Delete the subvolume now that all its descendants have been deleted - run(["btrfs", "subvol", "delete", path], - stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - def unlink_try_hard(path: Optional[Path]) -> None: if path is None: @@ -43,11 +18,4 @@ def unlink_try_hard(path: Optional[Path]) -> None: except Exception: pass - if shutil.which("btrfs"): - try: - btrfs_subvol_delete(path) - return - except Exception: - pass - shutil.rmtree(path)