Skip to content

Commit

Permalink
deltas: Add ostree_repo_list_static_delta_indexes() function
Browse files Browse the repository at this point in the history
This lists all the available delta indexes.
  • Loading branch information
alexlarsson committed Oct 23, 2020
1 parent 87e564e commit 8e1f199
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Makefile-libostree.am
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ libostree_1_la_SOURCES += \
endif # USE_GPGME

symbol_files = $(top_srcdir)/src/libostree/libostree-released.sym
#if BUILDOPT_IS_DEVEL_BUILD
#symbol_files += $(top_srcdir)/src/libostree/libostree-devel.sym
#endif
if BUILDOPT_IS_DEVEL_BUILD
symbol_files += $(top_srcdir)/src/libostree/libostree-devel.sym
endif
# http://blog.jgc.org/2007/06/escaping-comma-and-space-in-gnu-make.html
wl_versionscript_arg = -Wl,--version-script=
EXTRA_DIST += \
Expand Down
1 change: 1 addition & 0 deletions apidoc/ostree-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ OSTREE_REPO_LIST_OBJECTS_VARIANT_TYPE
ostree_repo_list_objects
ostree_repo_list_commit_objects_starting_with
ostree_repo_list_static_delta_names
ostree_repo_list_static_delta_indexes
OstreeStaticDeltaGenerateOpt
ostree_repo_static_delta_generate
ostree_repo_static_delta_execute_offline_with_signature
Expand Down
7 changes: 4 additions & 3 deletions src/libostree/libostree-devel.sym
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
Boston, MA 02111-1307, USA.
***/

/* Copy the bits below and uncomment the include in Makefile-libostree.am
when adding a symbol.
*/
LIBOSTREE_2020.8 {
global:
ostree_repo_list_static_delta_indexes;
} LIBOSTREE_2020.7;

/* Stub section for the stable release *after* this development one; don't
* edit this other than to update the year. This is just a copy/paste
Expand Down
87 changes: 87 additions & 0 deletions src/libostree/ostree-repo-static-delta-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,93 @@ ostree_repo_list_static_delta_names (OstreeRepo *self,
return TRUE;
}

/**
* ostree_repo_list_static_delta_indexes:
* @self: Repo
* @out_indexes: (out) (element-type utf8) (transfer container): String name of delta indexes (checksum)
* @cancellable: Cancellable
* @error: Error
*
* This function synchronously enumerates all static delta indexes in the
* repository, returning its result in @out_indexes.
*
* Since: 2020.7
*/
gboolean
ostree_repo_list_static_delta_indexes (OstreeRepo *self,
GPtrArray **out_indexes,
GCancellable *cancellable,
GError **error)
{
g_autoptr(GPtrArray) ret_indexes = g_ptr_array_new_with_free_func (g_free);

g_auto(GLnxDirFdIterator) dfd_iter = { 0, };
gboolean exists;
if (!ot_dfd_iter_init_allow_noent (self->repo_dir_fd, "delta-indexes", &dfd_iter,
&exists, error))
return FALSE;
if (!exists)
{
/* Note early return */
ot_transfer_out_value (out_indexes, &ret_indexes);
return TRUE;
}

while (TRUE)
{
g_auto(GLnxDirFdIterator) sub_dfd_iter = { 0, };
struct dirent *dent;

if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&dfd_iter, &dent, cancellable, error))
return FALSE;
if (dent == NULL)
break;
if (dent->d_type != DT_DIR)
continue;
if (strlen (dent->d_name) != 2)
continue;

if (!glnx_dirfd_iterator_init_at (dfd_iter.fd, dent->d_name, FALSE,
&sub_dfd_iter, error))
return FALSE;

while (TRUE)
{
struct dirent *sub_dent;

if (!glnx_dirfd_iterator_next_dent_ensure_dtype (&sub_dfd_iter, &sub_dent,
cancellable, error))
return FALSE;
if (sub_dent == NULL)
break;
if (sub_dent->d_type != DT_REG)
continue;

const char *name1 = dent->d_name;
const char *name2 = sub_dent->d_name;

/* base64 len is 43, but 2 chars are in the parent dir name */
if (strlen (name2) != 41 + strlen(".index") ||
!g_str_has_suffix (name2, ".index"))
continue;

g_autoptr(GString) out = g_string_new (name1);
g_string_append_len (out, name2, 41);

char checksum[OSTREE_SHA256_STRING_LEN+1];
guchar csum[OSTREE_SHA256_DIGEST_LEN];

ostree_checksum_b64_inplace_to_bytes (out->str, csum);
ostree_checksum_inplace_from_bytes (csum, checksum);

g_ptr_array_add (ret_indexes, g_strdup (checksum));
}
}

ot_transfer_out_value (out_indexes, &ret_indexes);
return TRUE;
}

gboolean
_ostree_repo_static_delta_part_have_all_objects (OstreeRepo *repo,
GVariant *checksum_array,
Expand Down
6 changes: 6 additions & 0 deletions src/libostree/ostree-repo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,12 @@ gboolean ostree_repo_list_static_delta_names (OstreeRepo *self,
GCancellable *cancellable,
GError **error);

_OSTREE_PUBLIC
gboolean ostree_repo_list_static_delta_indexes (OstreeRepo *self,
GPtrArray **out_indexes,
GCancellable *cancellable,
GError **error);

/**
* OstreeStaticDeltaGenerateOpt:
* @OSTREE_STATIC_DELTA_GENERATE_OPT_LOWLATENCY: Optimize for speed of delta creation over space
Expand Down

0 comments on commit 8e1f199

Please sign in to comment.