From 9c77e2ffe3763b2beb8a98e319b5c7c7c3c9b0e9 Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Fri, 6 Jan 2023 05:50:56 +0100 Subject: [PATCH] chroot: detect existing root mounts better --- chroot/base.py | 7 +++---- chroot/device.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/chroot/base.py b/chroot/base.py index 37ed943..48fdea3 100644 --- a/chroot/base.py +++ b/chroot/base.py @@ -2,12 +2,11 @@ import logging import os from glob import glob -from shutil import rmtree from typing import ClassVar from constants import Arch from exec.cmd import run_root_cmd -from exec.file import makedir, root_makedir +from exec.file import makedir, remove_file, root_makedir from config.state import config from .abstract import Chroot, get_chroot @@ -19,10 +18,10 @@ class BaseChroot(Chroot): _copy_base: ClassVar[bool] = False def create_rootfs(self, reset, pacman_conf_target, active_previously): - if reset: + if reset and os.path.exists(self.path): logging.info(f'Resetting {self.name}') for dir in glob(os.path.join(self.path, '*')): - rmtree(dir) + remove_file(dir, recursive=True) makedir(config.get_path('chroots')) root_makedir(self.get_path()) diff --git a/chroot/device.py b/chroot/device.py index bd04467..25730d0 100644 --- a/chroot/device.py +++ b/chroot/device.py @@ -42,7 +42,7 @@ class DeviceChroot(BuildChroot): really_active.append(mnt) if really_active: raise Exception(f'{self.name}: Chroot has submounts active: {really_active}') - if os.path.ismount(self.path): + if os.path.ismount(self.path) or check_findmnt(self.path): raise Exception(f'{self.name}: There is already something mounted at {self.path}, not mounting over it.') if os.path.exists(os.path.join(self.path, 'usr/bin')): raise Exception(f'{self.name}: {self.path}/usr/bin exists, not mounting over existing rootfs.')