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 <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2020-06-02 17:42:33 -07:00 committed by James Valleroy
parent d3b5143ed6
commit e59f9ac3fc
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -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,