From e59f9ac3fc2c806685f31cb0fc337a49de28b250 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 2 Jun 2020 17:42:33 -0700 Subject: [PATCH] storage: Ignore eject failures if filesystems unmounted properly Not all disks can be ejected. For example, SATA disks can't be ejected. However, they can be removed as long as all filesystems are unmounted properly. Ignore errors during ejecting of a disk. Closes: #1597. Tests performed: - In VirtualBox, attach a SATA disk, format it with two partitions. See them auto-mounted by FreedomBox. Eject one of the partitions, both partitions are unmounted but operation does not fail despite SATA disks not being eject-able. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- actions/storage | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/actions/storage b/actions/storage index 44da86c53..bf818d3de 100755 --- a/actions/storage +++ b/actions/storage @@ -281,6 +281,7 @@ def eject_drive_of_device(device_path): Return the details (model, vendor) of drives ejected. """ udisks = utils.import_from_gi('UDisks', '2.0') + glib = utils.import_from_gi('GLib', '2.0') client = udisks.Client.new_sync() object_manager = client.get_object_manager() @@ -307,7 +308,13 @@ def eject_drive_of_device(device_path): # Eject the drive drive = client.get_drive_for_block(block_device) if drive: - drive.call_eject_sync(_get_options(), None) + try: + drive.call_eject_sync(_get_options(), None) + except glib.Error: + # Ignore error during ejection as along as all the filesystems are + # unmounted, the disk can be removed. + pass + return { 'vendor': drive.props.vendor, 'model': drive.props.model,