[ostree] libotutil: new function ot_openat_ignore_enoent
- From: Giuseppe Scrivano <gscrivano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] libotutil: new function ot_openat_ignore_enoent
- Date: Tue, 15 Mar 2016 08:49:36 +0000 (UTC)
commit a98133072d0f44ac18a9a70669b0ffcd509620b8
Author: Giuseppe Scrivano <gscrivan redhat com>
Date: Fri Mar 11 11:36:21 2016 +0100
libotutil: new function ot_openat_ignore_enoent
Refactor some common code
Signed-off-by: Giuseppe Scrivano <gscrivan redhat com>
src/libostree/ostree-repo-refs.c | 34 ++++----------------------------
src/libostree/ostree-repo.c | 39 ++++++-------------------------------
src/libotutil/ot-fs-utils.c | 25 ++++++++++++++++++++++++
src/libotutil/ot-fs-utils.h | 5 ++++
4 files changed, 42 insertions(+), 61 deletions(-)
---
diff --git a/src/libostree/ostree-repo-refs.c b/src/libostree/ostree-repo-refs.c
index bf48006..0c03ad1 100644
--- a/src/libostree/ostree-repo-refs.c
+++ b/src/libostree/ostree-repo-refs.c
@@ -22,6 +22,7 @@
#include "ostree-repo-private.h"
#include "otutil.h"
+#include "ot-fs-utils.h"
static gboolean
add_ref_to_set (const char *remote,
@@ -115,31 +116,6 @@ write_checksum_file_at (OstreeRepo *self,
}
static gboolean
-openat_ignore_enoent (int dfd,
- const char *path,
- int *out_fd,
- GError **error)
-{
- gboolean ret = FALSE;
- int target_fd = -1;
-
- target_fd = openat (dfd, path, O_CLOEXEC | O_RDONLY);
- if (target_fd < 0)
- {
- if (errno != ENOENT)
- {
- glnx_set_error_from_errno (error);
- goto out;
- }
- }
-
- ret = TRUE;
- *out_fd = target_fd;
- out:
- return ret;
-}
-
-static gboolean
find_ref_in_remotes (OstreeRepo *self,
const char *rev,
int *out_fd,
@@ -168,7 +144,7 @@ find_ref_in_remotes (OstreeRepo *self,
if (!glnx_opendirat (dfd_iter.fd, dent->d_name, TRUE, &remote_dfd, error))
goto out;
- if (!openat_ignore_enoent (remote_dfd, rev, &ret_fd, error))
+ if (!ot_openat_ignore_enoent (remote_dfd, rev, &ret_fd, error))
goto out;
if (ret_fd != -1)
@@ -247,21 +223,21 @@ resolve_refspec (OstreeRepo *self,
{
const char *remote_ref = glnx_strjoina ("refs/remotes/", remote, "/", ref);
- if (!openat_ignore_enoent (self->repo_dir_fd, remote_ref, &target_fd, error))
+ if (!ot_openat_ignore_enoent (self->repo_dir_fd, remote_ref, &target_fd, error))
goto out;
}
else
{
const char *local_ref = glnx_strjoina ("refs/heads/", ref);
- if (!openat_ignore_enoent (self->repo_dir_fd, local_ref, &target_fd, error))
+ if (!ot_openat_ignore_enoent (self->repo_dir_fd, local_ref, &target_fd, error))
goto out;
if (target_fd == -1)
{
local_ref = glnx_strjoina ("refs/remotes/", ref);
- if (!openat_ignore_enoent (self->repo_dir_fd, local_ref, &target_fd, error))
+ if (!ot_openat_ignore_enoent (self->repo_dir_fd, local_ref, &target_fd, error))
goto out;
if (target_fd == -1)
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 752e097..2398c46 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -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"
@@ -2592,32 +2593,6 @@ list_loose_objects (OstreeRepo *self,
}
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,
const char *sha256,
@@ -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)
diff --git a/src/libotutil/ot-fs-utils.c b/src/libotutil/ot-fs-utils.c
index b709bef..ec27d76 100644
--- a/src/libotutil/ot-fs-utils.c
+++ b/src/libotutil/ot-fs-utils.c
@@ -205,3 +205,28 @@ ot_ensure_unlinked_at (int dfd,
}
return TRUE;
}
+
+gboolean
+ot_openat_ignore_enoent (int dfd,
+ const char *path,
+ int *out_fd,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ int target_fd = -1;
+
+ target_fd = openat (dfd, path, O_CLOEXEC | O_RDONLY);
+ if (target_fd < 0)
+ {
+ if (errno != ENOENT)
+ {
+ glnx_set_error_from_errno (error);
+ goto out;
+ }
+ }
+
+ ret = TRUE;
+ *out_fd = target_fd;
+ out:
+ return ret;
+}
diff --git a/src/libotutil/ot-fs-utils.h b/src/libotutil/ot-fs-utils.h
index 10686be..cfeea74 100644
--- a/src/libotutil/ot-fs-utils.h
+++ b/src/libotutil/ot-fs-utils.h
@@ -61,4 +61,9 @@ gboolean ot_ensure_unlinked_at (int dfd,
const char *path,
GError **error);
+gboolean ot_openat_ignore_enoent (int dfd,
+ const char *path,
+ int *out_fd,
+ GError **error);
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]