Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure to always query the right info before use #591

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
}
Loading