The new API is definitely nicer.
Closes: #1180
Approved by: jlebon
if (strcmp (dent->d_name, "cache") == 0)
continue;
- if (TEMP_FAILURE_RETRY (fstatat (dfd_iter.fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW)) < 0)
- {
- if (errno == ENOENT) /* Did another cleanup win? */
- continue;
- return glnx_throw_errno_prefix (error, "fstatat(%s)", dent->d_name);
- }
+ if (!glnx_fstatat_allow_noent (dfd_iter.fd, dent->d_name, &stbuf, AT_SYMLINK_NOFOLLOW, error))
+ return FALSE;
+ if (errno == ENOENT) /* Did another cleanup win? */
+ continue;
/* First, if it's a directory which needs locking, but it's
* busy, skip it.
GCancellable *cancellable,
GError **error)
{
- g_autoptr(GHashTable) ret_all_refs = NULL;
g_autofree char *remote = NULL;
g_autofree char *ref_prefix = NULL;
- ret_all_refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
-
+ g_autoptr(GHashTable) ret_all_refs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
if (refspec_prefix)
{
struct stat stbuf;
path = glnx_strjoina (prefix_path, ref_prefix);
}
- if (fstatat (self->repo_dir_fd, path, &stbuf, 0) < 0)
- {
- if (errno != ENOENT)
- return glnx_throw_errno (error);
- }
- else
+ if (!glnx_fstatat_allow_noent (self->repo_dir_fd, path, &stbuf, 0, error))
+ return FALSE;
+ if (errno == 0)
{
if (S_ISDIR (stbuf.st_mode))
{
/* Early return if we have an existing repo */
{ g_autofree char *objects_path = g_build_filename (path, "objects", NULL);
- if (fstatat (dfd, objects_path, &stbuf, 0) == 0)
+ if (!glnx_fstatat_allow_noent (dfd, objects_path, &stbuf, 0, error))
+ return FALSE;
+ if (errno == 0)
{
glnx_fd_close int repo_dfd = -1;
if (!glnx_opendirat (dfd, path, TRUE, &repo_dfd, error))
*out_dfd = glnx_steal_fd (&repo_dfd);
return TRUE;
}
- else if (errno != ENOENT)
- return glnx_throw_errno_prefix (error, "fstatat");
}
if (mkdirat (dfd, path, 0755) != 0)
if (!glnx_opendirat (dfd, path, TRUE, &repo_dfd, error))
return FALSE;
- if (fstatat (repo_dfd, "config", &stbuf, 0) < 0)
+ if (!glnx_fstatat_allow_noent (repo_dfd, "config", &stbuf, 0, error))
+ return FALSE;
+ if (errno == ENOENT)
{
- if (errno == ENOENT)
- {
- const char *mode_str = NULL;
- g_autoptr(GString) config_data = g_string_new (DEFAULT_CONFIG_CONTENTS);
+ const char *mode_str = NULL;
+ g_autoptr(GString) config_data = g_string_new (DEFAULT_CONFIG_CONTENTS);
- if (!ostree_repo_mode_to_string (mode, &mode_str, error))
- return FALSE;
- g_assert (mode_str);
+ if (!ostree_repo_mode_to_string (mode, &mode_str, error))
+ return FALSE;
+ g_assert (mode_str);
- g_string_append_printf (config_data, "mode=%s\n", mode_str);
+ g_string_append_printf (config_data, "mode=%s\n", mode_str);
- const char *collection_id = NULL;
- if (options)
- g_variant_lookup (options, "collection-id", "&s", &collection_id);
- if (collection_id != NULL)
- g_string_append_printf (config_data, "collection-id=%s\n", collection_id);
+ const char *collection_id = NULL;
+ if (options)
+ g_variant_lookup (options, "collection-id", "&s", &collection_id);
+ if (collection_id != NULL)
+ g_string_append_printf (config_data, "collection-id=%s\n", collection_id);
- if (!glnx_file_replace_contents_at (repo_dfd, "config",
- (guint8*)config_data->str, config_data->len,
- 0, cancellable, error))
- return FALSE;
- }
- else
- return glnx_throw_errno_prefix (error, "fstatat");
+ if (!glnx_file_replace_contents_at (repo_dfd, "config",
+ (guint8*)config_data->str, config_data->len,
+ 0, cancellable, error))
+ return FALSE;
}
for (guint i = 0; i < G_N_ELEMENTS (state_dirs); i++)
* when doing a deployment.
*/
const char selabeled[] = "var/.ostree-selabeled";
- gboolean deployment_var_labeled;
-
- if (!ot_query_exists_at (os_deploy_dfd, selabeled, &deployment_var_labeled, error))
+ struct stat stbuf;
+ if (!glnx_fstatat_allow_noent (os_deploy_dfd, selabeled, &stbuf, AT_SYMLINK_NOFOLLOW, error))
return FALSE;
-
- if (!deployment_var_labeled)
+ if (errno == ENOENT)
{
{ g_autofree char *msg =
g_strdup_printf ("Relabeling /var (no stamp file '%s' found)", selabeled);
}
}
- gboolean etc_exists = FALSE;
- if (!ot_query_exists_at (deployment_dfd, "etc", &etc_exists, error))
+ struct stat stbuf;
+ if (!glnx_fstatat_allow_noent (deployment_dfd, "etc", &stbuf, AT_SYMLINK_NOFOLLOW, error))
return FALSE;
- gboolean usretc_exists = FALSE;
- if (!ot_query_exists_at (deployment_dfd, "usr/etc", &usretc_exists, error))
+ gboolean etc_exists = (errno == 0);
+ if (!glnx_fstatat_allow_noent (deployment_dfd, "usr/etc", &stbuf, AT_SYMLINK_NOFOLLOW, error))
return FALSE;
+ gboolean usretc_exists = (errno == 0);
if (etc_exists && usretc_exists)
return glnx_throw (error, "Tree contains both /etc and /usr/etc");
* it doesn't exist already.
*/
struct stat stbuf;
- if (fstatat (bootcsum_dfd, kernel_layout->kernel_namever, &stbuf, 0) != 0)
+ if (!glnx_fstatat_allow_noent (bootcsum_dfd, kernel_layout->kernel_namever, &stbuf, 0, error))
+ return FALSE;
+ if (errno == ENOENT)
{
- if (errno != ENOENT)
- return glnx_throw_errno_prefix (error, "fstat %s", kernel_layout->kernel_namever);
if (!hardlink_or_copy_at (kernel_layout->boot_dfd,
kernel_layout->kernel_srcpath,
bootcsum_dfd, kernel_layout->kernel_namever,
if (kernel_layout->initramfs_srcpath)
{
g_assert (kernel_layout->initramfs_namever);
- if (fstatat (bootcsum_dfd, kernel_layout->initramfs_namever, &stbuf, 0) != 0)
+ if (!glnx_fstatat_allow_noent (bootcsum_dfd, kernel_layout->initramfs_namever, &stbuf, 0, error))
+ return FALSE;
+ if (errno == ENOENT)
{
- if (errno != ENOENT)
- return glnx_throw_errno_prefix (error, "fstat %s", kernel_layout->initramfs_namever);
if (!hardlink_or_copy_at (kernel_layout->boot_dfd, kernel_layout->initramfs_srcpath,
bootcsum_dfd, kernel_layout->initramfs_namever,
sysroot->debug_flags,
}
g_autofree char *contents = NULL;
- if (fstatat (deployment_dfd, "usr/lib/os-release", &stbuf, 0) != 0)
+ if (!glnx_fstatat_allow_noent (deployment_dfd, "usr/lib/os-release", &stbuf, 0, error))
+ return FALSE;
+ if (errno == ENOENT)
{
- if (errno != ENOENT)
- {
- return glnx_throw_errno (error);
- }
- else
- {
- contents = glnx_file_get_contents_utf8_at (deployment_dfd, "etc/os-release", NULL,
- cancellable, error);
- if (!contents)
- return glnx_prefix_error (error, "Reading /etc/os-release");
- }
+ contents = glnx_file_get_contents_utf8_at (deployment_dfd, "etc/os-release", NULL,
+ cancellable, error);
+ if (!contents)
+ return glnx_prefix_error (error, "Reading /etc/os-release");
}
else
{
g_autoptr(GKeyFile) ret_origin = g_key_file_new ();
struct stat stbuf;
- if (fstatat (deployment_dfd, origin_path, &stbuf, 0) != 0)
- {
- if (errno != ENOENT)
- return glnx_throw_errno (error);
- }
- else
+ if (!glnx_fstatat_allow_noent (deployment_dfd, origin_path, &stbuf, 0, error))
+ return FALSE;
+ if (errno == 0)
{
g_autofree char *origin_contents =
glnx_file_get_contents_utf8_at (deployment_dfd, origin_path,
return FALSE;
struct stat stbuf;
- if (fstatat (self->sysroot_fd, "ostree/deploy", &stbuf, 0) < 0)
- return glnx_throw_errno_prefix (error, "fstatat");
+ if (!glnx_fstatat (self->sysroot_fd, "ostree/deploy", &stbuf, 0, error))
+ return FALSE;
if (out_changed)
{
return TRUE;
}
-gboolean
-ot_query_exists_at (int dfd, const char *path,
- gboolean *out_exists,
- GError **error)
-{
- struct stat stbuf;
- gboolean ret_exists;
-
- if (fstatat (dfd, path, &stbuf, AT_SYMLINK_NOFOLLOW) < 0)
- {
- if (errno != ENOENT)
- return glnx_throw_errno_prefix (error, "fstatat(%s)", path);
- ret_exists = FALSE;
- }
- else
- ret_exists = TRUE;
-
- *out_exists = ret_exists;
- return TRUE;
-}
-
gboolean
ot_openat_ignore_enoent (int dfd,
const char *path,
GCancellable *cancellable,
GError **error);
-
-gboolean ot_query_exists_at (int dfd, const char *path,
- gboolean *out_exists,
- GError **error);
-
gboolean ot_ensure_unlinked_at (int dfd,
const char *path,
GError **error);