From bf056a9848460f9b107b3f3854d038dac16a4055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Mon, 19 Feb 2024 10:55:21 +0100 Subject: [PATCH] Make sure to always query the right info before use Also several cleanups regarding the code surrounding the GLib.FileInfo usage. --- .../file-bookmarks-plugin.vala | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/src/synapse-plugins/file-bookmarks-plugin.vala b/src/synapse-plugins/file-bookmarks-plugin.vala index 40a00997..2a15aa77 100644 --- a/src/synapse-plugins/file-bookmarks-plugin.vala +++ b/src/synapse-plugins/file-bookmarks-plugin.vala @@ -71,12 +71,15 @@ namespace Synapse { FileAttribute.STANDARD_CONTENT_TYPE, FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null ); - if (info.has_attribute (FileAttribute.STANDARD_CONTENT_TYPE)) { - appinfo = AppInfo.get_default_for_type ( - info.get_attribute_string (FileAttribute.STANDARD_CONTENT_TYPE), true - ); + unowned string? content_type = info.get_content_type (); + if (content_type != null) { + appinfo = AppInfo.get_default_for_type (content_type, true); } } catch (Error e) { + debug (e.message); + } + + if (appinfo == null) { appinfo = new DesktopAppInfo ("io.elementary.files.desktop"); } } @@ -148,15 +151,12 @@ namespace Synapse { FileInfo? info = null; try { - info = location.query_info ("", FileQueryInfoFlags.NONE); + info = location.query_info (GLib.FileAttribute.STANDARD_TARGET_URI, FileQueryInfoFlags.NONE); + target_uri = info.get_attribute_string (GLib.FileAttribute.STANDARD_TARGET_URI); } catch (GLib.Error err) { warning ("%s", err.message); } - if (info != null) { - target_uri = info.get_attribute_string (GLib.FileAttribute.STANDARD_TARGET_URI); - } - if (target_uri == null) { var uri = location.get_uri (); target_uri = uri; @@ -233,7 +233,7 @@ namespace Synapse { var file = GLib.File.new_for_path (filename); - if (yield query_exists_async (file)) { + if (yield Utils.query_exists_async (file)) { uint8[] contents_bytes; q.check_cancellable (); @@ -293,7 +293,7 @@ namespace Synapse { bool is_hidden = false; try { - var location_info = yield location.query_info_async ("", FileQueryInfoFlags.NONE); + var location_info = yield location.query_info_async (GLib.FileAttribute.STANDARD_IS_HIDDEN + ',' + GLib.FileAttribute.STANDARD_IS_BACKUP, FileQueryInfoFlags.NONE); is_hidden = location_info.get_is_hidden () || location_info.get_is_backup (); } catch (GLib.Error err) { @@ -336,15 +336,5 @@ namespace Synapse { return r; } - - private static async bool query_exists_async (File file) { - - try { - var info = yield file.query_info_async (FileAttribute.STANDARD_TYPE, FileQueryInfoFlags.NONE); - return info != null; - } catch (Error e) { - return false; - } - } } }