lib/repo: Add timestamps to OstreeRepoFinderResult
Currently OstreeRepoFinderResult, a data structure used by pull code that supports P2P operations, has a hash table mapping refs to checksums but doesn't include timestamp information. This means that clients have no way of knowing just from the OstreeRepoFinderResult information if a commit being offered by a peer remote is an update or downgrade until they start pulling it. The client could check the summary or the commit metadata for the timestamps, but this requires adding the temporary remotes to the repo config, and ostree is already checking timestamps before returning the results, so I think it makes more sense for them to be returned rather than leaving it to the client. This limitation is especially important for offline computers, because for online computers the latest commit available from any remote is the latest commit, period. This commit adds a "ref_to_timestamp" hash table to OstreeRepoFinderResult that is symmetric to "ref_to_checksum" in that it shares the same keys. This is an API break, but it's part of the experimental API, and none of the current users of that (flatpak, eos-updater, and gnome-software) are affected. See the documentation for more details on "ref_to_timestamp". One thing to note is the data structure currently gets initialized in find_remotes_cb(), so only users of ostree_repo_find_remotes_async() will get them, not users of, say, ostree_repo_finder_resolve_all_async(). This is because the individual OstreeRepoFinder implementations don't currently access the timestamps (but I think this could be changed in the future if there's a need). This commit will allow P2P support to be added to flatpak_installation_list_installed_refs_for_update, which will allow GNOME Software to update apps from USB drives while offline (it's already possible online). Closes: #1518 Approved by: cgwalters
This commit is contained in:
1 parent
c4c2b5ebd1
commit
cb3360fca6
8 files changed
+189
-9
No files matched your search
@@ -4862,6 +4862,7 @@ find_remotes_cb (GObject *obj,
|
||||
g_autoptr(GHashTable) commit_metadatas = NULL; /* (element-type commit-checksum CommitMetadata) */
|
||||
g_autoptr(OstreeFetcher) fetcher = NULL;
|
||||
g_autofree const gchar **ref_to_latest_commit = NULL; /* indexed as @refs; (element-type commit-checksum) */
|
||||
g_autofree guint64 *ref_to_latest_timestamp = NULL; /* indexed as @refs; (element-type commit-timestamp) */
|
||||
gsize n_refs;
|
||||
g_autofree char **override_commit_ids = NULL;
|
||||
g_autoptr(GPtrArray) remotes_to_remove = NULL; /* (element-type OstreeRemote) */
|
||||
@@ -5017,6 +5018,7 @@ find_remotes_cb (GObject *obj,
|
||||
* it’s been moved to @refs_and_remotes_table and is now potentially out
|
||||
* of date. */
|
||||
g_clear_pointer (&result->ref_to_checksum, g_hash_table_unref);
|
||||
g_clear_pointer (&result->ref_to_timestamp, g_hash_table_unref);
|
||||
result->summary_last_modified = summary_last_modified;
|
||||
}
|
||||
|
||||
@@ -5153,8 +5155,12 @@ find_remotes_cb (GObject *obj,
|
||||
*
|
||||
* @ref_to_latest_commit is indexed by @ref_index, and its values are the
|
||||
* latest checksum for each ref. If override-commit-ids was used,
|
||||
* @ref_to_latest_commit won't be initialized or used.*/
|
||||
* @ref_to_latest_commit won't be initialized or used.
|
||||
*
|
||||
* @ref_to_latest_timestamp is also indexed by @ref_index, and its values are
|
||||
* the latest timestamp for each ref, when available.*/
|
||||
ref_to_latest_commit = g_new0 (const gchar *, n_refs);
|
||||
ref_to_latest_timestamp = g_new0 (guint64, n_refs);
|
||||
|
||||
for (i = 0; i < n_refs; i++)
|
||||
{
|
||||
@@ -5195,6 +5201,11 @@ find_remotes_cb (GObject *obj,
|
||||
* the summary or commit metadata files above. */
|
||||
ref_to_latest_commit[i] = latest_checksum;
|
||||
|
||||
if (latest_checksum != NULL && latest_commit_metadata != NULL)
|
||||
ref_to_latest_timestamp[i] = latest_commit_metadata->timestamp;
|
||||
else
|
||||
ref_to_latest_timestamp[i] = 0;
|
||||
|
||||
if (latest_commit_metadata != NULL)
|
||||
{
|
||||
latest_commit_timestamp_str = uint64_secs_to_iso8601 (latest_commit_metadata->timestamp);
|
||||
@@ -5218,6 +5229,7 @@ find_remotes_cb (GObject *obj,
|
||||
{
|
||||
OstreeRepoFinderResult *result = g_ptr_array_index (results, i);
|
||||
g_autoptr(GHashTable) validated_ref_to_checksum = NULL; /* (element-type OstreeCollectionRef utf8) */
|
||||
g_autoptr(GHashTable) validated_ref_to_timestamp = NULL; /* (element-type OstreeCollectionRef guint64) */
|
||||
gsize j, n_latest_refs;
|
||||
|
||||
/* Previous error processing this result? */
|
||||
@@ -5231,11 +5243,24 @@ find_remotes_cb (GObject *obj,
|
||||
(GDestroyNotify) ostree_collection_ref_free,
|
||||
g_free);
|
||||
|
||||
validated_ref_to_timestamp = g_hash_table_new_full (ostree_collection_ref_hash,
|
||||
ostree_collection_ref_equal,
|
||||
(GDestroyNotify) ostree_collection_ref_free,
|
||||
g_free);
|
||||
if (override_commit_ids)
|
||||
{
|
||||
for (j = 0; refs[j] != NULL; j++)
|
||||
g_hash_table_insert (validated_ref_to_checksum, ostree_collection_ref_dup (refs[j]),
|
||||
g_strdup (override_commit_ids[j]));
|
||||
{
|
||||
guint64 *timestamp_ptr;
|
||||
|
||||
g_hash_table_insert (validated_ref_to_checksum, ostree_collection_ref_dup (refs[j]),
|
||||
g_strdup (override_commit_ids[j]));
|
||||
|
||||
timestamp_ptr = g_malloc (sizeof (guint64));
|
||||
*timestamp_ptr = 0;
|
||||
g_hash_table_insert (validated_ref_to_timestamp, ostree_collection_ref_dup (refs[j]),
|
||||
timestamp_ptr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -5244,6 +5269,7 @@ find_remotes_cb (GObject *obj,
|
||||
for (j = 0; refs[j] != NULL; j++)
|
||||
{
|
||||
const gchar *latest_commit_for_ref = ref_to_latest_commit[j];
|
||||
guint64 *timestamp_ptr;
|
||||
|
||||
if (pointer_table_get (refs_and_remotes_table, j, i) != latest_commit_for_ref)
|
||||
latest_commit_for_ref = NULL;
|
||||
@@ -5252,6 +5278,14 @@ find_remotes_cb (GObject *obj,
|
||||
|
||||
g_hash_table_insert (validated_ref_to_checksum, ostree_collection_ref_dup (refs[j]),
|
||||
g_strdup (latest_commit_for_ref));
|
||||
|
||||
timestamp_ptr = g_malloc (sizeof (guint64));
|
||||
if (latest_commit_for_ref != NULL)
|
||||
*timestamp_ptr = GUINT64_TO_BE (ref_to_latest_timestamp[j]);
|
||||
else
|
||||
*timestamp_ptr = 0;
|
||||
g_hash_table_insert (validated_ref_to_timestamp, ostree_collection_ref_dup (refs[j]),
|
||||
timestamp_ptr);
|
||||
}
|
||||
|
||||
if (n_latest_refs == 0)
|
||||
@@ -5264,6 +5298,7 @@ find_remotes_cb (GObject *obj,
|
||||
}
|
||||
|
||||
result->ref_to_checksum = g_steal_pointer (&validated_ref_to_checksum);
|
||||
result->ref_to_timestamp = g_steal_pointer (&validated_ref_to_timestamp);
|
||||
g_ptr_array_add (final_results, g_steal_pointer (&g_ptr_array_index (results, i)));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user