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 (stbuf.st_nlink == 1)
{ {
if (unlinkat (dfd_iter.fd, dent->d_name, 0) != 0) if (!glnx_unlinkat (dfd_iter.fd, dent->d_name, 0, error))
{ return FALSE;
glnx_set_error_from_errno (error);
return FALSE;
}
} }
} }
} }

View File

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

View File

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

View File

@ -1007,11 +1007,8 @@ _ostree_repo_write_ref (OstreeRepo *self,
{ {
if (dfd >= 0) if (dfd >= 0)
{ {
if (unlinkat (dfd, ref->ref_name, 0) != 0) if (!ot_ensure_unlinked_at (dfd, ref->ref_name, error))
{ return FALSE;
if (errno != ENOENT)
return glnx_throw_errno (error);
}
} }
} }
else if (rev != NULL) 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); _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 (!ot_ensure_unlinked_at (self->objects_dir_fd, meta_loose, error))
{ return FALSE;
if (G_UNLIKELY (errno != ENOENT))
return glnx_throw_errno_prefix (error, "unlinkat(%s)", meta_loose);
}
} }
if (TEMP_FAILURE_RETRY (unlinkat (self->objects_dir_fd, loose_path, 0)) < 0) if (!glnx_unlinkat (self->objects_dir_fd, loose_path, 0, error))
return glnx_throw_errno_prefix (error, "Deleting object %s.%s", sha256, ostree_object_type_to_string (objtype)); 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 the repository is configured to use tombstone commits, create one when deleting a commit. */
if (objtype == OSTREE_OBJECT_TYPE_COMMIT) if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
@ -5036,11 +5033,8 @@ ostree_repo_regenerate_summary (OstreeRepo *self,
error)) error))
return FALSE; return FALSE;
if (unlinkat (self->repo_dir_fd, "summary.sig", 0) < 0) if (!ot_ensure_unlinked_at (self->repo_dir_fd, "summary.sig", error))
{ return FALSE;
if (errno != ENOENT)
return glnx_throw_errno_prefix (error, "unlinkat");
}
return TRUE; return TRUE;
} }

View File

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