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:
parent
94eeae203b
commit
f9abbaca70
1 changed files with 32 additions and 20 deletions
|
@ -600,33 +600,45 @@ namespace
|
|||
|
||||
time_t get_file_mtime(Glib::RefPtr<Gio::File> const& file)
|
||||
{
|
||||
auto const info = file->query_info(G_FILE_ATTRIBUTE_TIME_MODIFIED);
|
||||
return info != nullptr ? info->get_attribute_uint64(G_FILE_ATTRIBUTE_TIME_MODIFIED) : 0;
|
||||
try
|
||||
{
|
||||
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)
|
||||
{
|
||||
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);
|
||||
auto const new_name = fmt::format("{}.added", old_name);
|
||||
info = file->query_info(G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
|
||||
}
|
||||
catch (Glib::Error const&)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
file->set_display_name(new_name);
|
||||
}
|
||||
catch (Glib::Error const& e)
|
||||
{
|
||||
auto const errmsg = fmt::format(
|
||||
_("Couldn't rename '{old_path}' as '{path}': {error} ({error_code})"),
|
||||
fmt::arg("old_path", old_name),
|
||||
fmt::arg("path", new_name),
|
||||
fmt::arg("error", e.what()),
|
||||
fmt::arg("error_code", e.code()));
|
||||
g_message("%s", errmsg.c_str());
|
||||
}
|
||||
auto const old_name = info->get_attribute_as_string(G_FILE_ATTRIBUTE_STANDARD_EDIT_NAME);
|
||||
auto const new_name = fmt::format("{}.added", old_name);
|
||||
|
||||
try
|
||||
{
|
||||
file->set_display_name(new_name);
|
||||
}
|
||||
catch (Glib::Error const& e)
|
||||
{
|
||||
auto const errmsg = fmt::format(
|
||||
_("Couldn't rename '{old_path}' as '{path}': {error} ({error_code})"),
|
||||
fmt::arg("old_path", old_name),
|
||||
fmt::arg("path", new_name),
|
||||
fmt::arg("error", e.what()),
|
||||
fmt::arg("error_code", e.code()));
|
||||
g_message("%s", errmsg.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue