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

+5 -29
View File
@@ -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,
@@ -114,31 +115,6 @@ write_checksum_file_at (OstreeRepo *self,
return ret;
}
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,
@@ -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)