Detach loopback device only if it was attached

Also change the print to better describe the action taken.
This commit is contained in:
Dor Askayo 2022-05-23 14:45:59 +03:00
parent 8c605f213a
commit 537cdb6540
1 changed files with 5 additions and 2 deletions

View File

@ -16,6 +16,9 @@ class SysC(SysGeneral):
""" """
Class responsible for preparing sources for System C. Class responsible for preparing sources for System C.
""" """
dev_name = None
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes
def __init__(self, arch, preserve_tmp, tmpdir, chroot): def __init__(self, arch, preserve_tmp, tmpdir, chroot):
self.git_dir = os.path.dirname(os.path.join(__file__)) self.git_dir = os.path.dirname(os.path.join(__file__))
@ -35,8 +38,8 @@ class SysC(SysGeneral):
def __del__(self): def __del__(self):
if not self.preserve_tmp: if not self.preserve_tmp:
if not self.chroot: if self.dev_name is not None:
print(f"Deleting {self.dev_name}") print(f"Detaching {self.dev_name}")
run('sudo', 'losetup', '-d', self.dev_name) run('sudo', 'losetup', '-d', self.dev_name)
super().__del__() super().__del__()