lib/util: Some style conversion

I saw a few instances of `glnx_set_error_from_errno() + return FALSE`,
and fixed them and did a bit of style conversion.

Closes: #895
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-05-30 13:04:18 -04:00 committed by Atomic Bot
parent 9a3555a74b
commit 2414704609
2 changed files with 13 additions and 51 deletions

View File

@ -97,24 +97,15 @@ ot_readlinkat_gfile_info (int dfd,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
char targetbuf[PATH_MAX+1]; char targetbuf[PATH_MAX+1];
ssize_t len; ssize_t len;
do if (TEMP_FAILURE_RETRY (len = readlinkat (dfd, path, targetbuf, sizeof (targetbuf) - 1)) < 0)
len = readlinkat (dfd, path, targetbuf, sizeof (targetbuf) - 1); return glnx_throw_errno_prefix (error, "readlinkat");
while (G_UNLIKELY (len == -1 && errno == EINTR));
if (len == -1)
{
glnx_set_error_from_errno (error);
goto out;
}
targetbuf[len] = '\0'; targetbuf[len] = '\0';
g_file_info_set_symlink_target (target_info, targetbuf); g_file_info_set_symlink_target (target_info, targetbuf);
ret = TRUE; return TRUE;
out:
return ret;
} }
@ -140,26 +131,17 @@ ot_openat_read_stream (int dfd,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
int fd = -1; int fd = -1;
int flags = O_RDONLY | O_NOCTTY | O_CLOEXEC; int flags = O_RDONLY | O_NOCTTY | O_CLOEXEC;
if (!follow) if (!follow)
flags |= O_NOFOLLOW; flags |= O_NOFOLLOW;
do if (TEMP_FAILURE_RETRY (fd = openat (dfd, path, flags, 0)) < 0)
fd = openat (dfd, path, flags, 0); return glnx_throw_errno_prefix (error, "openat(%s)", path);
while (G_UNLIKELY (fd == -1 && errno == EINTR));
if (fd == -1)
{
glnx_set_error_from_errno (error);
goto out;
}
*out_istream = g_unix_input_stream_new (fd, TRUE); *out_istream = g_unix_input_stream_new (fd, TRUE);
ret = TRUE; return TRUE;
out:
return ret;
} }
gboolean gboolean
@ -170,10 +152,7 @@ ot_ensure_unlinked_at (int dfd,
if (unlinkat (dfd, path, 0) != 0) if (unlinkat (dfd, path, 0) != 0)
{ {
if (G_UNLIKELY (errno != ENOENT)) if (G_UNLIKELY (errno != ENOENT))
{ return glnx_throw_errno_prefix (error, "unlink(%s)", path);
glnx_set_error_from_errno (error);
return FALSE;
}
} }
return TRUE; return TRUE;
} }
@ -189,10 +168,7 @@ ot_query_exists_at (int dfd, const char *path,
if (fstatat (dfd, path, &stbuf, AT_SYMLINK_NOFOLLOW) < 0) if (fstatat (dfd, path, &stbuf, AT_SYMLINK_NOFOLLOW) < 0)
{ {
if (errno != ENOENT) if (errno != ENOENT)
{ return glnx_throw_errno_prefix (error, "fstatat(%s)", path);
glnx_set_error_from_errno (error);
return FALSE;
}
ret_exists = FALSE; ret_exists = FALSE;
} }
else else
@ -208,23 +184,15 @@ ot_openat_ignore_enoent (int dfd,
int *out_fd, int *out_fd,
GError **error) GError **error)
{ {
gboolean ret = FALSE; int target_fd = openat (dfd, path, O_CLOEXEC | O_RDONLY);
int target_fd = -1;
target_fd = openat (dfd, path, O_CLOEXEC | O_RDONLY);
if (target_fd < 0) if (target_fd < 0)
{ {
if (errno != ENOENT) if (errno != ENOENT)
{ return glnx_throw_errno_prefix (error, "openat(%s)", path);
glnx_set_error_from_errno (error);
goto out;
}
} }
ret = TRUE;
*out_fd = target_fd; *out_fd = target_fd;
out: return TRUE;
return ret;
} }
/* Like glnx_dirfd_iterator_init_at(), but if %ENOENT, then set /* Like glnx_dirfd_iterator_init_at(), but if %ENOENT, then set
@ -261,10 +229,7 @@ ot_file_mapat_bytes (int dfd,
g_autoptr(GMappedFile) mfile = NULL; g_autoptr(GMappedFile) mfile = NULL;
if (fd < 0) if (fd < 0)
{ return glnx_null_throw_errno_prefix (error, "openat(%s)", path);
glnx_set_error_from_errno (error);
return FALSE;
}
mfile = g_mapped_file_new_from_fd (fd, FALSE, error); mfile = g_mapped_file_new_from_fd (fd, FALSE, error);
if (!mfile) if (!mfile)

View File

@ -100,10 +100,7 @@ ot_gfile_ensure_unlinked (GFile *path,
if (unlink (gs_file_get_path_cached (path)) != 0) if (unlink (gs_file_get_path_cached (path)) != 0)
{ {
if (errno != ENOENT) if (errno != ENOENT)
{ return glnx_throw_errno_prefix (error, "unlink(%s)", gs_file_get_path_cached (path));
glnx_set_error_from_errno (error);
return FALSE;
}
} }
return TRUE; return TRUE;
} }