1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-31 03:12:44 +00:00

Adjust Gio::File::query_info() error handling (GTK client) (#4079)

The method never returns `nullptr`, but instead throws if an error
occurs. This regressed during the switch from GTK to GTKMM.
This commit is contained in:
Mike Gelfand 2022-11-02 18:17:29 +01:00 committed by GitHub
parent 94eeae203b
commit f9abbaca70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -600,33 +600,45 @@ namespace
time_t get_file_mtime(Glib::RefPtr<Gio::File> const& file) time_t get_file_mtime(Glib::RefPtr<Gio::File> const& file)
{ {
auto const info = file->query_info(G_FILE_ATTRIBUTE_TIME_MODIFIED); try
return info != nullptr ? info->get_attribute_uint64(G_FILE_ATTRIBUTE_TIME_MODIFIED) : 0; {
return file->query_info(G_FILE_ATTRIBUTE_TIME_MODIFIED)->get_attribute_uint64(G_FILE_ATTRIBUTE_TIME_MODIFIED);
}
catch (Glib::Error const&)
{
return 0;
}
} }
void rename_torrent(Glib::RefPtr<Gio::File> const& file) void rename_torrent(Glib::RefPtr<Gio::File> const& file)
{ {
auto const info = file->query_info(G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME); auto info = Glib::RefPtr<Gio::FileInfo>();
if (info != nullptr) try
{ {
auto const old_name = info->get_attribute_as_string(G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME); info = file->query_info(G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
auto const new_name = fmt::format("{}.added", old_name); }
catch (Glib::Error const&)
{
return;
}
try auto const old_name = info->get_attribute_as_string(G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
{ auto const new_name = fmt::format("{}.added", old_name);
file->set_display_name(new_name);
} try
catch (Glib::Error const& e) {
{ file->set_display_name(new_name);
auto const errmsg = fmt::format( }
_("Couldn't rename '{old_path}' as '{path}': {error} ({error_code})"), catch (Glib::Error const& e)
fmt::arg("old_path", old_name), {
fmt::arg("path", new_name), auto const errmsg = fmt::format(
fmt::arg("error", e.what()), _("Couldn't rename '{old_path}' as '{path}': {error} ({error_code})"),
fmt::arg("error_code", e.code())); fmt::arg("old_path", old_name),
g_message("%s", errmsg.c_str()); fmt::arg("path", new_name),
} fmt::arg("error", e.what()),
fmt::arg("error_code", e.code()));
g_message("%s", errmsg.c_str());
} }
} }