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