[gnome-boxes] Media-manager: Refactor method to load "Detected Sources"
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Media-manager: Refactor method to load "Detected Sources"
- Date: Thu, 16 Dec 2021 14:36:06 +0000 (UTC)
commit 56849725815c94faecce2f22e8285cdf024bd666
Author: Felipe Borges <felipeborges gnome org>
Date: Thu Dec 16 15:06:20 2021 +0100
Media-manager: Refactor method to load "Detected Sources"
src/media-manager.vala | 84 ++++++++++++++++++++++++++++----------------------
1 file changed, 48 insertions(+), 36 deletions(-)
---
diff --git a/src/media-manager.vala b/src/media-manager.vala
index be211d54..3515ac7a 100644
--- a/src/media-manager.vala
+++ b/src/media-manager.vala
@@ -87,46 +87,19 @@ else if (VMConfigurator.is_libvirt_cloning_config (config))
public async GLib.List<InstallerMedia> list_installer_medias () {
var list = new GLib.List<InstallerMedia> ();
-#if !FLATPAK
- GUdev.Client client = new GUdev.Client ({"block"});
+ #if !FLATPAK
+ list.concat (yield load_physical_medias ());
+ #endif
- // First HW media
- var enumerator = new GUdev.Enumerator (client);
- // We don't want to deal with partitions to avoid duplicate medias
- enumerator.add_match_property ("DEVTYPE", "disk");
+ if (connection != null)
+ list.concat (yield load_medias_from_filesystem ());
- foreach (var device in enumerator.execute ()) {
- if (device.get_property ("ID_FS_BOOT_SYSTEM_ID") == null &&
- !device.get_property_as_boolean ("OSINFO_BOOTABLE"))
- continue;
-
- var path = device.get_device_file ();
- var file = File.new_for_path (path);
- try {
- var info = yield file.query_info_async (FileAttribute.ACCESS_CAN_READ,
- FileQueryInfoFlags.NONE,
- Priority.DEFAULT,
- null);
- if (!info.get_attribute_boolean (FileAttribute.ACCESS_CAN_READ)) {
- debug ("No read access to '%s', ignoring..", path);
- continue;
- }
-
- var media = yield create_installer_media_for_path (path);
-
- if (media != null) {
- list.append (media);
- }
- } catch (GLib.Error error) {
- warning ("Failed to get information on device '%s': %s. Ignoring..", path, error.message);
- }
- }
-#endif
+ return list;
+ }
- if (connection == null)
- return list;
+ private async GLib.List<InstallerMedia> load_medias_from_filesystem () {
+ var list = new GLib.List<InstallerMedia> ();
- // Now ISO files
try {
var query = yield new TrackerISOQuery (connection);
string path, title, os_id, media_id;
@@ -164,6 +137,45 @@ else if (VMConfigurator.is_libvirt_cloning_config (config))
return list;
}
+#if !FLATPAK
+ private async GLib.List<InstallerMedia> load_physical_medias ()
+ var list = GLib.List<InstallerMedia> list ();
+
+ GUdev.Client client = new GUdev.Client ({"block"});
+ var enumerator = new GUdev.Enumerator (client);
+ // We don't want to deal with partitions to avoid duplicate medias
+ enumerator.add_match_property ("DEVTYPE", "disk");
+
+ foreach (var device in enumerator.execute ()) {
+ if (device.get_property ("ID_FS_BOOT_SYSTEM_ID") == null &&
+ !device.get_property_as_boolean ("OSINFO_BOOTABLE"))
+ continue;
+
+ var path = device.get_device_file ();
+ var file = File.new_for_path (path);
+ try {
+ var info = yield file.query_info_async (FileAttribute.ACCESS_CAN_READ,
+ FileQueryInfoFlags.NONE,
+ Priority.DEFAULT,
+ null);
+ if (!info.get_attribute_boolean (FileAttribute.ACCESS_CAN_READ)) {
+ debug ("No read access to '%s', ignoring..", path);
+ continue;
+ }
+
+ var media = yield create_installer_media_for_path (path);
+ if (media != null) {
+ list.append (media);
+ }
+ } catch (GLib.Error error) {
+ message ("Failed to get information on device '%s': %s. Ignoring..", path, error.message);
+ }
+ }
+
+ return list;
+ }
+#endif
+
private static InstallerMedia create_unattended_installer (InstallerMedia media) throws GLib.Error {
InstallerMedia install_media = media;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]