libotutil: new function ot_openat_ignore_enoent

Refactor some common code

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano committed 2016-03-15 09:48:47 +01:00
1 parent 89514dd8ba
commit a98133072d
4 files changed
+42 -61

No files matched your search

+7 -32
View File
@@ -34,6 +34,7 @@
#include "ostree-repo-file-enumerator.h"
#include "ostree-gpg-verifier.h"
#include "ostree-repo-static-delta-private.h"
#include "ot-fs-utils.h"
#ifdef HAVE_LIBSOUP
#include "ostree-metalink.h"
@@ -2591,32 +2592,6 @@ list_loose_objects (OstreeRepo *self,
return ret;
}
static gboolean
openat_allow_noent (int dfd,
const char *path,
int *fd,
GCancellable *cancellable,
GError **error)
{
GError *temp_error = NULL;
if (!gs_file_openat_noatime (dfd, path, fd,
cancellable, &temp_error))
{
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{
*fd = -1;
g_clear_error (&temp_error);
}
else
{
g_propagate_error (error, temp_error);
return FALSE;
}
}
return TRUE;
}
static gboolean
load_metadata_internal (OstreeRepo *self,
OstreeObjectType objtype,
@@ -2638,14 +2613,14 @@ load_metadata_internal (OstreeRepo *self,
_ostree_loose_path (loose_path_buf, sha256, objtype, self->mode);
if (!openat_allow_noent (self->objects_dir_fd, loose_path_buf, &fd,
cancellable, error))
if (!ot_openat_ignore_enoent (self->objects_dir_fd, loose_path_buf, &fd,
error))
goto out;
if (fd < 0 && self->commit_stagedir_fd != -1)
{
if (!openat_allow_noent (self->commit_stagedir_fd, loose_path_buf, &fd,
cancellable, error))
if (!ot_openat_ignore_enoent (self->commit_stagedir_fd, loose_path_buf, &fd,
error))
goto out;
}
@@ -2839,8 +2814,8 @@ ostree_repo_load_file (OstreeRepo *self,
struct stat stbuf;
g_autoptr(GInputStream) tmp_stream = NULL;
if (!openat_allow_noent (self->objects_dir_fd, loose_path_buf, &fd,
cancellable, error))
if (!ot_openat_ignore_enoent (self->objects_dir_fd, loose_path_buf, &fd,
error))
goto out;
if (fd != -1)