mirror of
https://github.com/ostreedev/ostree.git
synced 2025-01-11 09:18:20 +03:00
libotutil: new function ot_openat_ignore_enoent
Refactor some common code Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
89514dd8ba
commit
a98133072d
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user