repo: Simplify internal has_object() lookup code
There was some leftover intermediate cruft here I noticed while reviewing another patch: - We had an output `GFile*` for that was never used - We required the caller to allocate the loose pathbuf, but none of them ever reused it - We had an extra intermediate function Also while looking at this, I'm now uncertain whether some of the callers of `_ostree_repo_has_loose_object` should really be invoking `ostree_repo_has_object()`, but let's leave that aside for now. Closes: #272 Approved by: alexlarsson
This commit is contained in:
parent
8f8ab56211
commit
8609cb036b
|
|
@ -573,11 +573,8 @@ _ostree_repo_open_trusted_content_bare (OstreeRepo *self,
|
||||||
g_autofree char *temp_filename = NULL;
|
g_autofree char *temp_filename = NULL;
|
||||||
g_autoptr(GOutputStream) ret_stream = NULL;
|
g_autoptr(GOutputStream) ret_stream = NULL;
|
||||||
gboolean have_obj;
|
gboolean have_obj;
|
||||||
char loose_objpath[_OSTREE_LOOSE_PATH_MAX];
|
|
||||||
|
|
||||||
if (!_ostree_repo_has_loose_object (self, checksum, OSTREE_OBJECT_TYPE_FILE,
|
if (!_ostree_repo_has_loose_object (self, checksum, OSTREE_OBJECT_TYPE_FILE, &have_obj,
|
||||||
&have_obj, loose_objpath,
|
|
||||||
NULL,
|
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
@ -662,7 +659,6 @@ write_object (OstreeRepo *self,
|
||||||
gboolean temp_file_is_regular;
|
gboolean temp_file_is_regular;
|
||||||
gboolean temp_file_is_symlink;
|
gboolean temp_file_is_symlink;
|
||||||
gboolean object_is_symlink = FALSE;
|
gboolean object_is_symlink = FALSE;
|
||||||
char loose_objpath[_OSTREE_LOOSE_PATH_MAX];
|
|
||||||
gssize unpacked_size = 0;
|
gssize unpacked_size = 0;
|
||||||
gboolean indexable = FALSE;
|
gboolean indexable = FALSE;
|
||||||
|
|
||||||
|
|
@ -673,9 +669,8 @@ write_object (OstreeRepo *self,
|
||||||
|
|
||||||
if (expected_checksum)
|
if (expected_checksum)
|
||||||
{
|
{
|
||||||
if (!_ostree_repo_has_loose_object (self, expected_checksum, objtype,
|
if (!_ostree_repo_has_loose_object (self, expected_checksum, objtype, &have_obj,
|
||||||
&have_obj, loose_objpath,
|
cancellable, error))
|
||||||
NULL, cancellable, error))
|
|
||||||
goto out;
|
goto out;
|
||||||
if (have_obj)
|
if (have_obj)
|
||||||
{
|
{
|
||||||
|
|
@ -852,8 +847,7 @@ write_object (OstreeRepo *self,
|
||||||
repo_store_size_entry (self, actual_checksum, unpacked_size, stbuf.st_size);
|
repo_store_size_entry (self, actual_checksum, unpacked_size, stbuf.st_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_ostree_repo_has_loose_object (self, actual_checksum, objtype,
|
if (!_ostree_repo_has_loose_object (self, actual_checksum, objtype, &have_obj,
|
||||||
&have_obj, loose_objpath, NULL,
|
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -135,8 +135,6 @@ _ostree_repo_has_loose_object (OstreeRepo *self,
|
||||||
const char *checksum,
|
const char *checksum,
|
||||||
OstreeObjectType objtype,
|
OstreeObjectType objtype,
|
||||||
gboolean *out_is_stored,
|
gboolean *out_is_stored,
|
||||||
char *loose_path_buf,
|
|
||||||
GFile **out_stored_path,
|
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3292,15 +3292,13 @@ _ostree_repo_has_loose_object (OstreeRepo *self,
|
||||||
const char *checksum,
|
const char *checksum,
|
||||||
OstreeObjectType objtype,
|
OstreeObjectType objtype,
|
||||||
gboolean *out_is_stored,
|
gboolean *out_is_stored,
|
||||||
char *loose_path_buf,
|
|
||||||
GFile **out_stored_path,
|
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
struct stat stbuf;
|
struct stat stbuf;
|
||||||
int res = -1;
|
int res = -1;
|
||||||
gboolean tmp_file = FALSE;
|
char loose_path_buf[_OSTREE_LOOSE_PATH_MAX];
|
||||||
|
|
||||||
_ostree_loose_path (loose_path_buf, checksum, objtype, self->mode);
|
_ostree_loose_path (loose_path_buf, checksum, objtype, self->mode);
|
||||||
|
|
||||||
|
|
@ -3316,9 +3314,7 @@ _ostree_repo_has_loose_object (OstreeRepo *self,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res == 0)
|
if (res < 0)
|
||||||
tmp_file = TRUE;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
res = fstatat (self->objects_dir_fd, loose_path_buf, &stbuf, AT_SYMLINK_NOFOLLOW);
|
res = fstatat (self->objects_dir_fd, loose_path_buf, &stbuf, AT_SYMLINK_NOFOLLOW);
|
||||||
|
|
@ -3332,32 +3328,10 @@ _ostree_repo_has_loose_object (OstreeRepo *self,
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
*out_is_stored = (res != -1);
|
*out_is_stored = (res != -1);
|
||||||
|
|
||||||
if (out_stored_path)
|
|
||||||
{
|
|
||||||
if (res != -1)
|
|
||||||
*out_stored_path = g_file_resolve_relative_path (tmp_file ? self->tmp_dir : self->objects_dir, loose_path_buf);
|
|
||||||
else
|
|
||||||
*out_stored_path = NULL;
|
|
||||||
}
|
|
||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
_ostree_repo_find_object (OstreeRepo *self,
|
|
||||||
OstreeObjectType objtype,
|
|
||||||
const char *checksum,
|
|
||||||
GFile **out_stored_path,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
gboolean has_object;
|
|
||||||
char loose_path[_OSTREE_LOOSE_PATH_MAX];
|
|
||||||
return _ostree_repo_has_loose_object (self, checksum, objtype, &has_object, loose_path,
|
|
||||||
out_stored_path, cancellable, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ostree_repo_has_object:
|
* ostree_repo_has_object:
|
||||||
* @self: Repo
|
* @self: Repo
|
||||||
|
|
@ -3382,13 +3356,12 @@ ostree_repo_has_object (OstreeRepo *self,
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
gboolean ret_have_object;
|
gboolean ret_have_object;
|
||||||
g_autoptr(GFile) loose_path = NULL;
|
|
||||||
|
|
||||||
if (!_ostree_repo_find_object (self, objtype, checksum, &loose_path,
|
if (!_ostree_repo_has_loose_object (self, checksum, objtype, &ret_have_object,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
ret_have_object = (loose_path != NULL);
|
/* In the future, here is where we would also look up in metadata pack files */
|
||||||
|
|
||||||
if (!ret_have_object && self->parent_repo)
|
if (!ret_have_object && self->parent_repo)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue