]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Remove btrfs subvolume deletion logic
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 31 Jan 2023 18:37:28 +0000 (19:37 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 1 Feb 2023 09:28:03 +0000 (10:28 +0100)
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.

mkosi/remove.py

index 29ed078d5ef837f6e72f4d35e3191fe5991d94a6..aa0d0241363d6c566c0be144c1954b637c588a8a 100644 (file)
@@ -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)