From 641ab260697d160cdff3de54dd7430279d30acb0 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Fri, 28 Jul 2023 03:14:50 +0300 Subject: [PATCH] fix(storage): fix root device detection and ignore iso9660 --- selfprivacy_api/graphql/queries/storage.py | 2 +- selfprivacy_api/services/generic_service_mover.py | 2 +- selfprivacy_api/utils/block_devices.py | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/selfprivacy_api/graphql/queries/storage.py b/selfprivacy_api/graphql/queries/storage.py index 6800518..4b9a291 100644 --- a/selfprivacy_api/graphql/queries/storage.py +++ b/selfprivacy_api/graphql/queries/storage.py @@ -23,7 +23,7 @@ class Storage: else str(volume.size), free_space=str(volume.fsavail), used_space=str(volume.fsused), - root=volume.name == "sda1", + root=volume.is_root(), name=volume.name, model=volume.model, serial=volume.serial, diff --git a/selfprivacy_api/services/generic_service_mover.py b/selfprivacy_api/services/generic_service_mover.py index d858b93..cfb0385 100644 --- a/selfprivacy_api/services/generic_service_mover.py +++ b/selfprivacy_api/services/generic_service_mover.py @@ -83,7 +83,7 @@ def move_service( ) return # Make sure the volume is mounted - if volume.name != "sda1" and f"/volumes/{volume.name}" not in volume.mountpoints: + if not volume.is_root() and f"/volumes/{volume.name}" not in volume.mountpoints: Jobs.update( job=job, status=JobStatus.ERROR, diff --git a/selfprivacy_api/utils/block_devices.py b/selfprivacy_api/utils/block_devices.py index 15b6979..83fc28f 100644 --- a/selfprivacy_api/utils/block_devices.py +++ b/selfprivacy_api/utils/block_devices.py @@ -71,6 +71,12 @@ class BlockDevice: def __hash__(self): return hash(self.name) + def is_root(self) -> bool: + """ + Return True if the block device is the root device. + """ + return "/" in self.mountpoints + def stats(self) -> typing.Dict[str, typing.Any]: """ Update current data and return a dictionary of stats. @@ -175,6 +181,9 @@ class BlockDevices(metaclass=SingletonMetaclass): # Ignore devices with type "rom" if device["type"] == "rom": continue + # Ignore iso9660 devices + if device["fstype"] == "iso9660": + continue if device["fstype"] is None: if "children" in device: for child in device["children"]: