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