tree-wide: Use helpers for unlinkat()

We have `ot_ensure_unlinked_at()` for the "ignore ENOENT" case, and
`glnx_unlinkat()` otherwise. Port all in-tree callers to one or the other as
appropriate.

Just noticed an unprefixed error in the refs case and decided to do a tree-wide
check.

Closes: #1142
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-09-06 11:37:02 -04:00 committed by Atomic Bot
parent 57509e4d50
commit 303320163f
6 changed files with 16 additions and 36 deletions

View File

@ -1121,11 +1121,8 @@ ostree_repo_checkout_gc (OstreeRepo *self,
if (stbuf.st_nlink == 1)
{
if (unlinkat (dfd_iter.fd, dent->d_name, 0) != 0)
{
glnx_set_error_from_errno (error);
return FALSE;
}
if (!glnx_unlinkat (dfd_iter.fd, dent->d_name, 0, error))
return FALSE;
}
}
}

View File

@ -43,13 +43,7 @@ prune_commitpartial_file (OstreeRepo *repo,
GError **error)
{
g_autofree char *path = _ostree_get_commitpartial_path (checksum);
if (unlinkat (repo->repo_dir_fd, path, 0) != 0)
{
if (errno != ENOENT)
return glnx_throw_errno_prefix (error, "unlinkat");
}
return TRUE;
return ot_ensure_unlinked_at (repo->repo_dir_fd, path, error);
}
static gboolean
@ -147,8 +141,8 @@ _ostree_repo_prune_tmp (OstreeRepo *self,
if (has_sig_suffix)
dent->d_name[len - 4] = '.';
if (unlinkat (dfd_iter.fd, dent->d_name, 0) < 0)
return glnx_throw_errno_prefix (error, "unlinkat");
if (!glnx_unlinkat (dfd_iter.fd, dent->d_name, 0, error))
return FALSE;
}
}

View File

@ -1357,11 +1357,8 @@ static_deltapart_fetch_on_complete (GObject *object,
goto out;
/* From here on, if we fail to apply the delta, we'll re-fetch it */
if (unlinkat (_ostree_fetcher_get_dfd (fetcher), temp_path, 0) < 0)
{
glnx_set_error_from_errno (error);
goto out;
}
if (!glnx_unlinkat (_ostree_fetcher_get_dfd (fetcher), temp_path, 0, error))
goto out;
in = g_unix_input_stream_new (fd, FALSE);

View File

@ -1007,11 +1007,8 @@ _ostree_repo_write_ref (OstreeRepo *self,
{
if (dfd >= 0)
{
if (unlinkat (dfd, ref->ref_name, 0) != 0)
{
if (errno != ENOENT)
return glnx_throw_errno (error);
}
if (!ot_ensure_unlinked_at (dfd, ref->ref_name, error))
return FALSE;
}
}
else if (rev != NULL)

View File

@ -3256,15 +3256,12 @@ ostree_repo_delete_object (OstreeRepo *self,
_ostree_loose_path (meta_loose, sha256, OSTREE_OBJECT_TYPE_COMMIT_META, self->mode);
if (TEMP_FAILURE_RETRY (unlinkat (self->objects_dir_fd, meta_loose, 0)) < 0)
{
if (G_UNLIKELY (errno != ENOENT))
return glnx_throw_errno_prefix (error, "unlinkat(%s)", meta_loose);
}
if (!ot_ensure_unlinked_at (self->objects_dir_fd, meta_loose, error))
return FALSE;
}
if (TEMP_FAILURE_RETRY (unlinkat (self->objects_dir_fd, loose_path, 0)) < 0)
return glnx_throw_errno_prefix (error, "Deleting object %s.%s", sha256, ostree_object_type_to_string (objtype));
if (!glnx_unlinkat (self->objects_dir_fd, loose_path, 0, error))
return glnx_prefix_error (error, "Deleting object %s.%s", sha256, ostree_object_type_to_string (objtype));
/* If the repository is configured to use tombstone commits, create one when deleting a commit. */
if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
@ -5036,11 +5033,8 @@ ostree_repo_regenerate_summary (OstreeRepo *self,
error))
return FALSE;
if (unlinkat (self->repo_dir_fd, "summary.sig", 0) < 0)
{
if (errno != ENOENT)
return glnx_throw_errno_prefix (error, "unlinkat");
}
if (!ot_ensure_unlinked_at (self->repo_dir_fd, "summary.sig", error))
return FALSE;
return TRUE;
}

View File

@ -90,6 +90,7 @@ ot_openat_read_stream (int dfd,
return TRUE;
}
/* Like unlinkat() but ignore ENOENT */
gboolean
ot_ensure_unlinked_at (int dfd,
const char *path,