fileutils: Avoid calling set_file_error with NULL GError**

If no pointer to a GError* has been passed to public API, there's not
need to look at translations via gettext or format an error message that
g_set_error_literal will entirely ignore in the end.
This commit is contained in:
Timm Bäder 2020-12-31 11:28:03 +01:00
parent 423bfa87d5
commit 03ca87586f

View File

@ -897,6 +897,8 @@ get_contents_posix (const gchar *filename,
if (fd < 0)
{
int saved_errno = errno;
if (error)
set_file_error (error,
filename,
_("Failed to open file “%s”: %s"),
@ -909,6 +911,7 @@ get_contents_posix (const gchar *filename,
if (fstat (fd, &stat_buf) < 0)
{
int saved_errno = errno;
if (error)
set_file_error (error,
filename,
_("Failed to get attributes of file “%s”: fstat() failed: %s"),
@ -939,6 +942,7 @@ get_contents_posix (const gchar *filename,
if (f == NULL)
{
int saved_errno = errno;
if (error)
set_file_error (error,
filename,
_("Failed to open file “%s”: fdopen() failed: %s"),
@ -969,6 +973,7 @@ get_contents_win32 (const gchar *filename,
if (f == NULL)
{
int saved_errno = errno;
if (error)
set_file_error (error,
filename,
_("Failed to open file “%s”: %s"),
@ -1165,6 +1170,7 @@ write_to_file (const gchar *contents,
if (saved_errno == EINTR)
continue;
if (err)
set_file_error (err,
dest_file, _("Failed to write file “%s”: write() failed: %s"),
saved_errno);
@ -1185,6 +1191,7 @@ write_to_file (const gchar *contents,
if (do_fsync && g_fsync (fd) != 0)
{
int saved_errno = errno;
if (err)
set_file_error (err,
dest_file, _("Failed to write file “%s”: fsync() failed: %s"),
saved_errno);
@ -1353,6 +1360,7 @@ g_file_set_contents_full (const gchar *filename,
if (fd == -1)
{
int saved_errno = errno;
if (error)
set_file_error (error,
tmp_filename, _("Failed to create file “%s”: %s"),
saved_errno);
@ -1396,6 +1404,7 @@ g_file_set_contents_full (const gchar *filename,
if (g_unlink (filename) == -1)
{
int saved_errno = errno;
if (error)
set_file_error (error,
filename,
_("Existing file “%s” could not be removed: g_unlink() failed: %s"),
@ -1462,6 +1471,7 @@ consistent_out:
mode, error);
#endif /* O_NOFOLLOW */
if (error)
set_file_error (error,
filename, _("Failed to open file “%s”: %s"),
saved_errno);
@ -1764,6 +1774,7 @@ g_get_tmp_name (const gchar *tmpl,
if (retval == -1)
{
int saved_errno = errno;
if (error)
set_file_error (error,
fulltemplate,
_("Failed to create file “%s”: %s"),
@ -2301,6 +2312,7 @@ g_file_read_link (const gchar *filename,
if (read_size < 0)
{
int saved_errno = errno;
if (error)
set_file_error (error,
filename,
_("Failed to read the symbolic link “%s”: %s"),
@ -2329,6 +2341,7 @@ g_file_read_link (const gchar *filename,
if (read_size < 0)
{
int saved_errno = errno;
if (error)
set_file_error (error,
filename,
_("Failed to read the symbolic link “%s”: %s"),