Skip to content

Commit

Permalink
Make sure to always query the right info before use
Browse files Browse the repository at this point in the history
Also several cleanups regarding the code surrounding the GLib.FileInfo usage.
  • Loading branch information
tintou committed Feb 20, 2024
1 parent 01b96d1 commit 7001334
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/synapse-plugins/file-bookmarks-plugin.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
}
}

0 comments on commit 7001334

Please sign in to comment.