Refactor get_device() into if fail return early pattern

To follow a code pattern slowly being applied.
This commit is contained in:
Mike Fleetwood 2024-09-08 21:05:12 +01:00
parent eb04be7b03
commit 8d9321917b
1 changed files with 23 additions and 27 deletions

View File

@ -4095,38 +4095,34 @@ bool GParted_Core::flush_device( PedDevice * lp_device )
bool GParted_Core::get_device( const Glib::ustring & device_path, PedDevice *& lp_device, bool flush )
{
lp_device = ped_device_get(device_path.c_str());
if ( lp_device )
{
if (! lp_device)
return false;
if (flush)
{
#ifdef ENABLE_EXPLICIT_FLUSH_WORKAROUND
// Force cache coherency explicitly ourselves with libparted < 3.2
// which doesn't flush the Linux kernel caches when opening
// devices. This is so that libparted reading the whole disk
// device and file system tools reading the partition devices read
// the same data.
// Force cache coherency explicitly ourselves with libparted < 3.2 which
// doesn't flush the Linux kernel caches when opening devices. This is so
// that libparted reading the whole disk device and file system tools
// reading the partition devices read the same data.
flush_device(lp_device);
#endif
// (!46) Wait for udev rules to complete after either GParted
// explicit device flush or libparted inbuilt device flush in
// ped_device_get(). This is to avoid busy /dev/DISK entry when
// running file system specific query commands on the whole disk
// device in the call sequence after get_device(..., flush=true)
// in set_device_from_disk().
// (!46) Wait for udev rules to complete after either GParted explicit
// device flush or libparted inbuilt device flush in ped_device_get().
// This is to avoid busy /dev/DISK entry when running file system specific
// query commands on the whole disk device in the call sequence after
// get_device(..., flush=true) in set_device_from_disk().
//
// This is still needed even with libparted 3.6 because a whole
// disk device FAT32 file system looks like it's partitioned and
// This is still needed even with libparted 3.6 because a whole disk
// device FAT32 file system looks like it's partitioned and
// ped_device_get() still opens partition devices read-write when
// flushing, so still triggers device changes and udev rule
// execution.
// flushing, so still triggers device changes and udev rule execution.
settle_device(SETTLE_DEVICE_PROBE_MAX_WAIT_SECONDS);
}
return true;
}
return false;
}
bool GParted_Core::get_disk(PedDevice *lp_device, PedDisk*& lp_disk)