diff options
Diffstat (limited to 'src/libostree/ostree-repo-pull.c')
-rw-r--r-- | src/libostree/ostree-repo-pull.c | 3156 |
1 files changed, 1408 insertions, 1748 deletions
diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c index 77aa452e..7c0598a8 100644 --- a/src/libostree/ostree-repo-pull.c +++ b/src/libostree/ostree-repo-pull.c @@ -26,22 +26,22 @@ #include "config.h" #include "libglnx.h" +#include "ostree-repo-pull-private.h" #include "ostree.h" #include "otutil.h" -#include "ostree-repo-pull-private.h" #ifdef HAVE_LIBCURL_OR_LIBSOUP #include "ostree-core-private.h" -#include "ostree-repo-static-delta-private.h" #include "ostree-metalink.h" +#include "ostree-repo-static-delta-private.h" -#include "ostree-repo-finder.h" #include "ostree-repo-finder-config.h" #include "ostree-repo-finder-mount.h" +#include "ostree-repo-finder.h" #ifdef HAVE_AVAHI #include "ostree-repo-finder-avahi.h" -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ #include <gio/gunixinputstream.h> #include <sys/statvfs.h> @@ -50,9 +50,10 @@ #include <systemd/sd-journal.h> #endif -#define OSTREE_MESSAGE_FETCH_COMPLETE_ID SD_ID128_MAKE(75,ba,3d,eb,0a,f0,41,a9,a4,62,72,ff,85,d9,e7,3e) +#define OSTREE_MESSAGE_FETCH_COMPLETE_ID \ + SD_ID128_MAKE (75, ba, 3d, eb, 0a, f0, 41, a9, a4, 62, 72, ff, 85, d9, e7, 3e) -#define OSTREE_REPO_PULL_CONTENT_PRIORITY (OSTREE_FETCHER_DEFAULT_PRIORITY) +#define OSTREE_REPO_PULL_CONTENT_PRIORITY (OSTREE_FETCHER_DEFAULT_PRIORITY) #define OSTREE_REPO_PULL_METADATA_PRIORITY (OSTREE_REPO_PULL_CONTENT_PRIORITY - 100) /* Arbitrarily chosen number of retries for all download operations when they @@ -61,23 +62,25 @@ * `n-network-retries` pull option. */ #define DEFAULT_N_NETWORK_RETRIES 5 -typedef struct { - OtPullData *pull_data; - GVariant *object; - char *path; - gboolean is_detached_meta; +typedef struct +{ + OtPullData *pull_data; + GVariant *object; + char *path; + gboolean is_detached_meta; /* Only relevant when is_detached_meta is TRUE. Controls * whether to fetch the primary object after fetching its * detached metadata (no need if it's already stored). */ - gboolean object_is_stored; + gboolean object_is_stored; - OstreeCollectionRef *requested_ref; /* (nullable) */ + OstreeCollectionRef *requested_ref; /* (nullable) */ guint n_retries_remaining; } FetchObjectData; -typedef struct { - OtPullData *pull_data; +typedef struct +{ + OtPullData *pull_data; GVariant *objects; char *expected_checksum; char *from_revision; @@ -87,27 +90,30 @@ typedef struct { guint n_retries_remaining; } FetchStaticDeltaData; -typedef struct { +typedef struct +{ guchar csum[OSTREE_SHA256_DIGEST_LEN]; char *path; OstreeObjectType objtype; - guint recursion_depth; /* NB: not used anymore, though might be nice to print */ - OstreeCollectionRef *requested_ref; /* (nullable) */ + guint recursion_depth; /* NB: not used anymore, though might be nice to print */ + OstreeCollectionRef *requested_ref; /* (nullable) */ } ScanObjectQueueData; -typedef struct { +typedef struct +{ OtPullData *pull_data; char *from_revision; char *to_revision; - OstreeCollectionRef *requested_ref; /* (nullable) */ + OstreeCollectionRef *requested_ref; /* (nullable) */ guint n_retries_remaining; } FetchDeltaSuperData; -typedef struct { +typedef struct +{ OtPullData *pull_data; char *from_revision; char *to_revision; - OstreeCollectionRef *requested_ref; /* (nullable) */ + OstreeCollectionRef *requested_ref; /* (nullable) */ guint n_retries_remaining; } FetchDeltaIndexData; @@ -119,53 +125,38 @@ variant_or_null_unref (gpointer data) } static void start_fetch (OtPullData *pull_data, FetchObjectData *fetch); -static void start_fetch_deltapart (OtPullData *pull_data, - FetchStaticDeltaData *fetch); -static void start_fetch_delta_superblock (OtPullData *pull_data, - FetchDeltaSuperData *fetch_data); -static void start_fetch_delta_index (OtPullData *pull_data, - FetchDeltaIndexData *fetch_data); +static void start_fetch_deltapart (OtPullData *pull_data, FetchStaticDeltaData *fetch); +static void start_fetch_delta_superblock (OtPullData *pull_data, FetchDeltaSuperData *fetch_data); +static void start_fetch_delta_index (OtPullData *pull_data, FetchDeltaIndexData *fetch_data); static gboolean fetcher_queue_is_full (OtPullData *pull_data); -static void queue_scan_one_metadata_object (OtPullData *pull_data, - const char *csum, - OstreeObjectType objtype, - const char *path, - guint recursion_depth, - const OstreeCollectionRef *ref); - -static void queue_scan_one_metadata_object_s (OtPullData *pull_data, - ScanObjectQueueData *scan_data); -static void queue_scan_one_metadata_object_c (OtPullData *pull_data, - const guchar *csum, - OstreeObjectType objtype, - const char *path, - guint recursion_depth, +static void queue_scan_one_metadata_object (OtPullData *pull_data, const char *csum, + OstreeObjectType objtype, const char *path, + guint recursion_depth, const OstreeCollectionRef *ref); + +static void queue_scan_one_metadata_object_s (OtPullData *pull_data, + ScanObjectQueueData *scan_data); +static void queue_scan_one_metadata_object_c (OtPullData *pull_data, const guchar *csum, + OstreeObjectType objtype, const char *path, + guint recursion_depth, const OstreeCollectionRef *ref); -static void enqueue_one_object_request_s (OtPullData *pull_data, - FetchObjectData *fetch_data); -static void enqueue_one_static_delta_index_request_s (OtPullData *pull_data, +static void enqueue_one_object_request_s (OtPullData *pull_data, FetchObjectData *fetch_data); +static void enqueue_one_static_delta_index_request_s (OtPullData *pull_data, FetchDeltaIndexData *fetch_data); -static void enqueue_one_static_delta_superblock_request_s (OtPullData *pull_data, +static void enqueue_one_static_delta_superblock_request_s (OtPullData *pull_data, FetchDeltaSuperData *fetch_data); -static void enqueue_one_static_delta_part_request_s (OtPullData *pull_data, +static void enqueue_one_static_delta_part_request_s (OtPullData *pull_data, FetchStaticDeltaData *fetch_data); static void ensure_idle_queued (OtPullData *pull_data); -static gboolean scan_one_metadata_object (OtPullData *pull_data, - const char *checksum, - OstreeObjectType objtype, - const char *path, - guint recursion_depth, - const OstreeCollectionRef *ref, - GCancellable *cancellable, - GError **error); +static gboolean scan_one_metadata_object (OtPullData *pull_data, const char *checksum, + OstreeObjectType objtype, const char *path, + guint recursion_depth, const OstreeCollectionRef *ref, + GCancellable *cancellable, GError **error); static void scan_object_queue_data_free (ScanObjectQueueData *scan_data); -static gboolean initiate_delta_request (OtPullData *pull_data, - const OstreeCollectionRef *ref, - const char *to_revision, - const char *delta_from_revision, - GError **error); +static gboolean initiate_delta_request (OtPullData *pull_data, const OstreeCollectionRef *ref, + const char *to_revision, const char *delta_from_revision, + GError **error); static gboolean update_progress (gpointer user_data) @@ -181,63 +172,51 @@ update_progress (gpointer user_data) pull_data = user_data; - if (! pull_data->progress) + if (!pull_data->progress) return FALSE; /* In dry run, we only emit progress once metadata is done */ if (pull_data->dry_run && pull_data->n_outstanding_metadata_fetches > 0) return TRUE; - outstanding_writes = pull_data->n_outstanding_content_write_requests + - pull_data->n_outstanding_metadata_write_requests + - pull_data->n_outstanding_deltapart_write_requests; - outstanding_fetches = pull_data->n_outstanding_content_fetches + - pull_data->n_outstanding_metadata_fetches + - pull_data->n_outstanding_deltapart_fetches; + outstanding_writes = pull_data->n_outstanding_content_write_requests + + pull_data->n_outstanding_metadata_write_requests + + pull_data->n_outstanding_deltapart_write_requests; + outstanding_fetches = pull_data->n_outstanding_content_fetches + + pull_data->n_outstanding_metadata_fetches + + pull_data->n_outstanding_deltapart_fetches; bytes_transferred = _ostree_fetcher_bytes_transferred (pull_data->fetcher); fetched = pull_data->n_fetched_metadata + pull_data->n_fetched_content; requested = pull_data->n_requested_metadata + pull_data->n_requested_content; n_scanned_metadata = pull_data->n_scanned_metadata; start_time = pull_data->start_time; - ostree_async_progress_set (pull_data->progress, - "outstanding-fetches", "u", outstanding_fetches, - "outstanding-writes", "u", outstanding_writes, - "fetched", "u", fetched, - "requested", "u", requested, - "scanning", "u", g_queue_is_empty (&pull_data->scan_object_queue) ? 0 : 1, - "caught-error", "b", pull_data->caught_error, - "scanned-metadata", "u", n_scanned_metadata, - "bytes-transferred", "t", bytes_transferred, - "start-time", "t", start_time, - /* We use these status keys even though we now also - * use these values for filesystem-local pulls. - */ - "metadata-fetched-localcache", "u", pull_data->n_imported_metadata, - "content-fetched-localcache", "u", pull_data->n_imported_content, - /* Deltas */ - "fetched-delta-parts", - "u", pull_data->n_fetched_deltaparts, - "total-delta-parts", - "u", pull_data->n_total_deltaparts, - "fetched-delta-fallbacks", - "u", pull_data->n_fetched_deltapart_fallbacks, - "total-delta-fallbacks", - "u", pull_data->n_total_delta_fallbacks, - "fetched-delta-part-size", - "t", pull_data->fetched_deltapart_size, - "total-delta-part-size", - "t", pull_data->total_deltapart_size, - "total-delta-part-usize", - "t", pull_data->total_deltapart_usize, - "total-delta-superblocks", - "u", pull_data->static_delta_superblocks->len, - /* We fetch metadata before content. These allow us to report metadata fetch progress specifically. */ - "outstanding-metadata-fetches", "u", pull_data->n_outstanding_metadata_fetches, - "metadata-fetched", "u", pull_data->n_fetched_metadata, - /* Overall status. */ - "status", "s", "", - NULL); + ostree_async_progress_set ( + pull_data->progress, "outstanding-fetches", "u", outstanding_fetches, "outstanding-writes", + "u", outstanding_writes, "fetched", "u", fetched, "requested", "u", requested, "scanning", + "u", g_queue_is_empty (&pull_data->scan_object_queue) ? 0 : 1, "caught-error", "b", + pull_data->caught_error, "scanned-metadata", "u", n_scanned_metadata, "bytes-transferred", + "t", bytes_transferred, "start-time", "t", start_time, + /* We use these status keys even though we now also + * use these values for filesystem-local pulls. + */ + "metadata-fetched-localcache", "u", pull_data->n_imported_metadata, + "content-fetched-localcache", "u", pull_data->n_imported_content, + /* Deltas */ + "fetched-delta-parts", "u", pull_data->n_fetched_deltaparts, "total-delta-parts", "u", + pull_data->n_total_deltaparts, "fetched-delta-fallbacks", "u", + pull_data->n_fetched_deltapart_fallbacks, "total-delta-fallbacks", "u", + pull_data->n_total_delta_fallbacks, "fetched-delta-part-size", "t", + pull_data->fetched_deltapart_size, "total-delta-part-size", "t", + pull_data->total_deltapart_size, "total-delta-part-usize", "t", + pull_data->total_deltapart_usize, "total-delta-superblocks", "u", + pull_data->static_delta_superblocks->len, + /* We fetch metadata before content. These allow us to report metadata fetch progress + specifically. */ + "outstanding-metadata-fetches", "u", pull_data->n_outstanding_metadata_fetches, + "metadata-fetched", "u", pull_data->n_fetched_metadata, + /* Overall status. */ + "status", "s", "", NULL); if (pull_data->dry_run) pull_data->dry_run_emitted_progress = TRUE; @@ -247,14 +226,14 @@ update_progress (gpointer user_data) /* The core logic function for whether we should continue the main loop */ static gboolean -pull_termination_condition (OtPullData *pull_data) +pull_termination_condition (OtPullData *pull_data) { - gboolean current_fetch_idle = (pull_data->n_outstanding_metadata_fetches == 0 && - pull_data->n_outstanding_content_fetches == 0 && - pull_data->n_outstanding_deltapart_fetches == 0); - gboolean current_write_idle = (pull_data->n_outstanding_metadata_write_requests == 0 && - pull_data->n_outstanding_content_write_requests == 0 && - pull_data->n_outstanding_deltapart_write_requests == 0 ); + gboolean current_fetch_idle = (pull_data->n_outstanding_metadata_fetches == 0 + && pull_data->n_outstanding_content_fetches == 0 + && pull_data->n_outstanding_deltapart_fetches == 0); + gboolean current_write_idle = (pull_data->n_outstanding_metadata_write_requests == 0 + && pull_data->n_outstanding_content_write_requests == 0 + && pull_data->n_outstanding_deltapart_write_requests == 0); gboolean current_scan_idle = g_queue_is_empty (&pull_data->scan_object_queue); gboolean current_idle = current_fetch_idle && current_write_idle && current_scan_idle; @@ -275,8 +254,7 @@ pull_termination_condition (OtPullData *pull_data) * requests as appropriate. */ static void -check_outstanding_requests_handle_error (OtPullData *pull_data, - GError **errorp) +check_outstanding_requests_handle_error (OtPullData *pull_data, GError **errorp) { g_assert (errorp); @@ -301,7 +279,7 @@ check_outstanding_requests_handle_error (OtPullData *pull_data, */ if (pull_data->caught_error) { - g_queue_foreach (&pull_data->scan_object_queue, (GFunc) scan_object_queue_data_free, NULL); + g_queue_foreach (&pull_data->scan_object_queue, (GFunc)scan_object_queue_data_free, NULL); g_queue_clear (&pull_data->scan_object_queue); g_hash_table_remove_all (pull_data->pending_fetch_metadata); g_hash_table_remove_all (pull_data->pending_fetch_delta_indexes); @@ -323,8 +301,7 @@ check_outstanding_requests_handle_error (OtPullData *pull_data, /* Try filling the queue with metadata we need to fetch */ g_hash_table_iter_init (&hiter, pull_data->pending_fetch_metadata); - while (!fetcher_queue_is_full (pull_data) && - g_hash_table_iter_next (&hiter, &key, &value)) + while (!fetcher_queue_is_full (pull_data) && g_hash_table_iter_next (&hiter, &key, &value)) { GVariant *objname = key; FetchObjectData *fetch = value; @@ -340,8 +317,7 @@ check_outstanding_requests_handle_error (OtPullData *pull_data, /* Next, process delta index requests */ g_hash_table_iter_init (&hiter, pull_data->pending_fetch_delta_indexes); - while (!fetcher_queue_is_full (pull_data) && - g_hash_table_iter_next (&hiter, &key, &value)) + while (!fetcher_queue_is_full (pull_data) && g_hash_table_iter_next (&hiter, &key, &value)) { FetchDeltaIndexData *fetch = key; g_hash_table_iter_steal (&hiter); @@ -350,8 +326,7 @@ check_outstanding_requests_handle_error (OtPullData *pull_data, /* Next, process delta superblock requests */ g_hash_table_iter_init (&hiter, pull_data->pending_fetch_delta_superblocks); - while (!fetcher_queue_is_full (pull_data) && - g_hash_table_iter_next (&hiter, &key, &value)) + while (!fetcher_queue_is_full (pull_data) && g_hash_table_iter_next (&hiter, &key, &value)) { FetchDeltaSuperData *fetch = key; g_hash_table_iter_steal (&hiter); @@ -360,8 +335,7 @@ check_outstanding_requests_handle_error (OtPullData *pull_data, /* Now, process deltapart requests */ g_hash_table_iter_init (&hiter, pull_data->pending_fetch_deltaparts); - while (!fetcher_queue_is_full (pull_data) && - g_hash_table_iter_next (&hiter, &key, &value)) + while (!fetcher_queue_is_full (pull_data) && g_hash_table_iter_next (&hiter, &key, &value)) { FetchStaticDeltaData *fetch = key; g_hash_table_iter_steal (&hiter); @@ -371,8 +345,7 @@ check_outstanding_requests_handle_error (OtPullData *pull_data, /* Next, fill the queue with content */ g_hash_table_iter_init (&hiter, pull_data->pending_fetch_content); - while (!fetcher_queue_is_full (pull_data) && - g_hash_table_iter_next (&hiter, &key, &value)) + while (!fetcher_queue_is_full (pull_data) && g_hash_table_iter_next (&hiter, &key, &value)) { char *checksum = key; FetchObjectData *fetch = value; @@ -400,19 +373,16 @@ check_outstanding_requests_handle_error (OtPullData *pull_data, static gboolean fetcher_queue_is_full (OtPullData *pull_data) { - const gboolean fetch_full = - ((pull_data->n_outstanding_metadata_fetches + - pull_data->n_outstanding_content_fetches + - pull_data->n_outstanding_deltapart_fetches) == - _OSTREE_MAX_OUTSTANDING_FETCHER_REQUESTS); - const gboolean deltas_full = - (pull_data->n_outstanding_deltapart_fetches == - _OSTREE_MAX_OUTSTANDING_DELTAPART_REQUESTS); - const gboolean writes_full = - ((pull_data->n_outstanding_metadata_write_requests + - pull_data->n_outstanding_content_write_requests + - pull_data->n_outstanding_deltapart_write_requests) >= - _OSTREE_MAX_OUTSTANDING_WRITE_REQUESTS); + const gboolean fetch_full + = ((pull_data->n_outstanding_metadata_fetches + pull_data->n_outstanding_content_fetches + + pull_data->n_outstanding_deltapart_fetches) + == _OSTREE_MAX_OUTSTANDING_FETCHER_REQUESTS); + const gboolean deltas_full + = (pull_data->n_outstanding_deltapart_fetches == _OSTREE_MAX_OUTSTANDING_DELTAPART_REQUESTS); + const gboolean writes_full = ((pull_data->n_outstanding_metadata_write_requests + + pull_data->n_outstanding_content_write_requests + + pull_data->n_outstanding_deltapart_write_requests) + >= _OSTREE_MAX_OUTSTANDING_WRITE_REQUESTS); return fetch_full || deltas_full || writes_full; } @@ -435,7 +405,7 @@ idle_worker (gpointer user_data) { OtPullData *pull_data = user_data; ScanObjectQueueData *scan_data; - g_autoptr(GError) error = NULL; + g_autoptr (GError) error = NULL; scan_data = g_queue_pop_head (&pull_data->scan_object_queue); if (!scan_data) @@ -444,11 +414,11 @@ idle_worker (gpointer user_data) return G_SOURCE_REMOVE; } - char checksum[OSTREE_SHA256_STRING_LEN+1]; + char checksum[OSTREE_SHA256_STRING_LEN + 1]; ostree_checksum_inplace_from_bytes (scan_data->csum, checksum); - scan_one_metadata_object (pull_data, checksum, scan_data->objtype, - scan_data->path, scan_data->recursion_depth, - scan_data->requested_ref, pull_data->cancellable, &error); + scan_one_metadata_object (pull_data, checksum, scan_data->objtype, scan_data->path, + scan_data->recursion_depth, scan_data->requested_ref, + pull_data->cancellable, &error); /* No need to retry scan tasks, since they’re local. */ check_outstanding_requests_handle_error (pull_data, &error); @@ -477,28 +447,23 @@ ensure_idle_queued (OtPullData *pull_data) g_source_unref (idle_src); } -typedef struct { - OtPullData *pull_data; - GInputStream *result_stream; +typedef struct +{ + OtPullData *pull_data; + GInputStream *result_stream; } OstreeFetchUriSyncData; static gboolean -fetch_mirrored_uri_contents_utf8_sync (OstreeFetcher *fetcher, - GPtrArray *mirrorlist, - const char *filename, - guint n_network_retries, - char **out_contents, - GCancellable *cancellable, - GError **error) +fetch_mirrored_uri_contents_utf8_sync (OstreeFetcher *fetcher, GPtrArray *mirrorlist, + const char *filename, guint n_network_retries, + char **out_contents, GCancellable *cancellable, + GError **error) { - g_autoptr(GBytes) bytes = NULL; - if (!_ostree_fetcher_mirrored_request_to_membuf (fetcher, mirrorlist, - filename, OSTREE_FETCHER_REQUEST_NUL_TERMINATION, - NULL, 0, - n_network_retries, - &bytes, NULL, NULL, NULL, - OSTREE_MAX_METADATA_SIZE, - cancellable, error)) + g_autoptr (GBytes) bytes = NULL; + if (!_ostree_fetcher_mirrored_request_to_membuf (fetcher, mirrorlist, filename, + OSTREE_FETCHER_REQUEST_NUL_TERMINATION, NULL, 0, + n_network_retries, &bytes, NULL, NULL, NULL, + OSTREE_MAX_METADATA_SIZE, cancellable, error)) return FALSE; gsize len; @@ -512,34 +477,23 @@ fetch_mirrored_uri_contents_utf8_sync (OstreeFetcher *fetcher, } static gboolean -fetch_uri_contents_utf8_sync (OstreeFetcher *fetcher, - OstreeFetcherURI *uri, - guint n_network_retries, - char **out_contents, - GCancellable *cancellable, - GError **error) +fetch_uri_contents_utf8_sync (OstreeFetcher *fetcher, OstreeFetcherURI *uri, + guint n_network_retries, char **out_contents, + GCancellable *cancellable, GError **error) { - g_autoptr(GPtrArray) mirrorlist = g_ptr_array_new (); + g_autoptr (GPtrArray) mirrorlist = g_ptr_array_new (); g_ptr_array_add (mirrorlist, uri); /* no transfer */ - return fetch_mirrored_uri_contents_utf8_sync (fetcher, mirrorlist, - NULL, n_network_retries, - out_contents, - cancellable, error); + return fetch_mirrored_uri_contents_utf8_sync (fetcher, mirrorlist, NULL, n_network_retries, + out_contents, cancellable, error); } -static void -enqueue_one_object_request (OtPullData *pull_data, - const char *checksum, - OstreeObjectType objtype, - const char *path, - gboolean is_detached_meta, - gboolean object_is_stored, - const OstreeCollectionRef *ref); +static void enqueue_one_object_request (OtPullData *pull_data, const char *checksum, + OstreeObjectType objtype, const char *path, + gboolean is_detached_meta, gboolean object_is_stored, + const OstreeCollectionRef *ref); static gboolean -matches_pull_dir (const char *current_file, - const char *pull_dir, - gboolean current_file_is_dir) +matches_pull_dir (const char *current_file, const char *pull_dir, gboolean current_file_is_dir) { const char *rest; @@ -577,11 +531,8 @@ matches_pull_dir (const char *current_file, return FALSE; } - static gboolean -pull_matches_subdir (OtPullData *pull_data, - const char *path, - const char *basename, +pull_matches_subdir (OtPullData *pull_data, const char *path, const char *basename, gboolean basename_is_dir) { if (pull_data->dirs == NULL) @@ -599,28 +550,26 @@ pull_matches_subdir (OtPullData *pull_data, return FALSE; } -typedef struct { +typedef struct +{ OtPullData *pull_data; OstreeRepo *src_repo; - char checksum[OSTREE_SHA256_STRING_LEN+1]; + char checksum[OSTREE_SHA256_STRING_LEN + 1]; } ImportLocalAsyncData; /* Asynchronously import a single content object. @src_repo is either * pull_data->remote_repo_local or one of pull_data->localcache_repos. */ static void -async_import_in_thread (GTask *task, - gpointer source, - gpointer task_data, - GCancellable *cancellable) +async_import_in_thread (GTask *task, gpointer source, gpointer task_data, GCancellable *cancellable) { ImportLocalAsyncData *iataskdata = task_data; OtPullData *pull_data = iataskdata->pull_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; /* pull_data->importflags was set up in the pull option processing */ - if (!_ostree_repo_import_object (pull_data->repo, iataskdata->src_repo, - OSTREE_OBJECT_TYPE_FILE, iataskdata->checksum, - pull_data->importflags, cancellable, &local_error)) + if (!_ostree_repo_import_object (pull_data->repo, iataskdata->src_repo, OSTREE_OBJECT_TYPE_FILE, + iataskdata->checksum, pull_data->importflags, cancellable, + &local_error)) g_task_return_error (task, g_steal_pointer (&local_error)); else g_task_return_boolean (task, TRUE); @@ -634,18 +583,15 @@ async_import_in_thread (GTask *task, * OSTREE_REPO_PULL_FLAGS_BAREUSERONLY_FILES flag. */ static void -async_import_one_local_content_object (OtPullData *pull_data, - OstreeRepo *src_repo, - const char *checksum, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +async_import_one_local_content_object (OtPullData *pull_data, OstreeRepo *src_repo, + const char *checksum, GCancellable *cancellable, + GAsyncReadyCallback callback, gpointer user_data) { ImportLocalAsyncData *iataskdata = g_new0 (ImportLocalAsyncData, 1); iataskdata->pull_data = pull_data; iataskdata->src_repo = src_repo; memcpy (iataskdata->checksum, checksum, OSTREE_SHA256_STRING_LEN); - g_autoptr(GTask) task = g_task_new (pull_data->repo, cancellable, callback, user_data); + g_autoptr (GTask) task = g_task_new (pull_data->repo, cancellable, callback, user_data); g_task_set_source_tag (task, async_import_one_local_content_object); g_task_set_task_data (task, iataskdata, g_free); pull_data->n_outstanding_content_write_requests++; @@ -653,27 +599,24 @@ async_import_one_local_content_object (OtPullData *pull_data, } static gboolean -async_import_one_local_content_object_finish (OtPullData *pull_data, - GAsyncResult *result, +async_import_one_local_content_object_finish (OtPullData *pull_data, GAsyncResult *result, GError **error) { g_return_val_if_fail (g_task_is_valid (result, pull_data->repo), FALSE); - return g_task_propagate_boolean ((GTask*)result, error); + return g_task_propagate_boolean ((GTask *)result, error); } static void -on_local_object_imported (GObject *object, - GAsyncResult *result, - gpointer user_data) +on_local_object_imported (GObject *object, GAsyncResult *result, gpointer user_data) { OtPullData *pull_data = user_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; if (!async_import_one_local_content_object_finish (pull_data, result, error)) goto out; - out: +out: pull_data->n_imported_content++; g_assert_cmpint (pull_data->n_outstanding_content_write_requests, >, 0); pull_data->n_outstanding_content_write_requests--; @@ -682,26 +625,22 @@ on_local_object_imported (GObject *object, } static gboolean -scan_dirtree_object (OtPullData *pull_data, - const char *checksum, - const char *path, - int recursion_depth, - GCancellable *cancellable, - GError **error) +scan_dirtree_object (OtPullData *pull_data, const char *checksum, const char *path, + int recursion_depth, GCancellable *cancellable, GError **error) { - g_autoptr(GVariant) tree = NULL; - if (!ostree_repo_load_variant (pull_data->repo, OSTREE_OBJECT_TYPE_DIR_TREE, checksum, - &tree, error)) + g_autoptr (GVariant) tree = NULL; + if (!ostree_repo_load_variant (pull_data->repo, OSTREE_OBJECT_TYPE_DIR_TREE, checksum, &tree, + error)) return FALSE; /* PARSE OSTREE_SERIALIZED_TREE_VARIANT */ - g_autoptr(GVariant) files_variant = g_variant_get_child_value (tree, 0); + g_autoptr (GVariant) files_variant = g_variant_get_child_value (tree, 0); const guint n = g_variant_n_children (files_variant); for (guint i = 0; i < n; i++) { const char *filename; gboolean file_is_stored; - g_autoptr(GVariant) csum = NULL; + g_autoptr (GVariant) csum = NULL; g_autofree char *file_checksum = NULL; g_variant_get_child (files_variant, i, "(&s@ay)", &filename, &csum); @@ -739,8 +678,7 @@ scan_dirtree_object (OtPullData *pull_data, { async_import_one_local_content_object (pull_data, pull_data->remote_repo_local, file_checksum, cancellable, - on_local_object_imported, - pull_data); + on_local_object_imported, pull_data); g_hash_table_add (pull_data->requested_content, g_steal_pointer (&file_checksum)); /* Note early loop continue */ continue; @@ -760,8 +698,9 @@ scan_dirtree_object (OtPullData *pull_data, return FALSE; if (!localcache_repo_has_obj) continue; - async_import_one_local_content_object (pull_data, localcache_repo, file_checksum, cancellable, - on_local_object_imported, pull_data); + async_import_one_local_content_object (pull_data, localcache_repo, file_checksum, + cancellable, on_local_object_imported, + pull_data); g_hash_table_add (pull_data->requested_content, g_steal_pointer (&file_checksum)); did_import_from_cache_repo = TRUE; break; @@ -772,19 +711,19 @@ scan_dirtree_object (OtPullData *pull_data, /* Not available locally, queue a HTTP request */ g_hash_table_add (pull_data->requested_content, file_checksum); - enqueue_one_object_request (pull_data, file_checksum, OSTREE_OBJECT_TYPE_FILE, path, FALSE, FALSE, NULL); - file_checksum = NULL; /* Transfer ownership */ + enqueue_one_object_request (pull_data, file_checksum, OSTREE_OBJECT_TYPE_FILE, path, FALSE, + FALSE, NULL); + file_checksum = NULL; /* Transfer ownership */ } - g_autoptr(GVariant) dirs_variant = g_variant_get_child_value (tree, 1); + g_autoptr (GVariant) dirs_variant = g_variant_get_child_value (tree, 1); const guint m = g_variant_n_children (dirs_variant); for (guint i = 0; i < m; i++) { const char *dirname = NULL; - g_autoptr(GVariant) tree_csum = NULL; - g_autoptr(GVariant) meta_csum = NULL; - g_variant_get_child (dirs_variant, i, "(&s@ay@ay)", - &dirname, &tree_csum, &meta_csum); + g_autoptr (GVariant) tree_csum = NULL; + g_autoptr (GVariant) meta_csum = NULL; + g_variant_get_child (dirs_variant, i, "(&s@ay@ay)", &dirname, &tree_csum, &meta_csum); /* See comment above for files */ if (!ot_util_filename_validate (dirname, error)) @@ -802,10 +741,10 @@ scan_dirtree_object (OtPullData *pull_data, return FALSE; g_autofree char *subpath = g_strconcat (path, dirname, "/", NULL); - queue_scan_one_metadata_object_c (pull_data, tree_csum_bytes, - OSTREE_OBJECT_TYPE_DIR_TREE, subpath, recursion_depth + 1, NULL); - queue_scan_one_metadata_object_c (pull_data, meta_csum_bytes, - OSTREE_OBJECT_TYPE_DIR_META, subpath, recursion_depth + 1, NULL); + queue_scan_one_metadata_object_c (pull_data, tree_csum_bytes, OSTREE_OBJECT_TYPE_DIR_TREE, + subpath, recursion_depth + 1, NULL); + queue_scan_one_metadata_object_c (pull_data, meta_csum_bytes, OSTREE_OBJECT_TYPE_DIR_META, + subpath, recursion_depth + 1, NULL); } return TRUE; @@ -813,29 +752,23 @@ scan_dirtree_object (OtPullData *pull_data, /* Given a @ref, fetch its contents (should be a SHA256 ASCII string) */ static gboolean -fetch_ref_contents (OtPullData *pull_data, - const char *main_collection_id, - const OstreeCollectionRef *ref, - char **out_contents, - GCancellable *cancellable, - GError **error) +fetch_ref_contents (OtPullData *pull_data, const char *main_collection_id, + const OstreeCollectionRef *ref, char **out_contents, GCancellable *cancellable, + GError **error) { g_autofree char *ret_contents = NULL; if (pull_data->remote_repo_local != NULL && ref->collection_id != NULL) { - if (!ostree_repo_resolve_collection_ref (pull_data->remote_repo_local, - ref, FALSE, - OSTREE_REPO_RESOLVE_REV_EXT_NONE, - &ret_contents, cancellable, error)) + if (!ostree_repo_resolve_collection_ref (pull_data->remote_repo_local, ref, FALSE, + OSTREE_REPO_RESOLVE_REV_EXT_NONE, &ret_contents, + cancellable, error)) return FALSE; } else if (pull_data->remote_repo_local != NULL) { - if (!ostree_repo_resolve_rev_ext (pull_data->remote_repo_local, - ref->ref_name, FALSE, - OSTREE_REPO_RESOLVE_REV_EXT_NONE, - &ret_contents, error)) + if (!ostree_repo_resolve_rev_ext (pull_data->remote_repo_local, ref->ref_name, FALSE, + OSTREE_REPO_RESOLVE_REV_EXT_NONE, &ret_contents, error)) return FALSE; } else @@ -847,11 +780,9 @@ fetch_ref_contents (OtPullData *pull_data, else filename = g_build_filename ("refs", "mirrors", ref->collection_id, ref->ref_name, NULL); - if (!fetch_mirrored_uri_contents_utf8_sync (pull_data->fetcher, - pull_data->meta_mirrorlist, + if (!fetch_mirrored_uri_contents_utf8_sync (pull_data->fetcher, pull_data->meta_mirrorlist, filename, pull_data->n_network_retries, - &ret_contents, - cancellable, error)) + &ret_contents, cancellable, error)) return FALSE; g_strchomp (ret_contents); @@ -861,28 +792,26 @@ fetch_ref_contents (OtPullData *pull_data, if (!ostree_validate_checksum_string (ret_contents, error)) return glnx_prefix_error (error, "Fetching checksum for ref (%s, %s)", - ref->collection_id ?: "(empty)", - ref->ref_name); + ref->collection_id ?: "(empty)", ref->ref_name); ot_transfer_out_value (out_contents, &ret_contents); return TRUE; } static gboolean -lookup_commit_checksum_and_collection_from_summary (OtPullData *pull_data, - const OstreeCollectionRef *ref, - char **out_checksum, - gsize *out_size, - char **out_collection_id, - GError **error) +lookup_commit_checksum_and_collection_from_summary (OtPullData *pull_data, + const OstreeCollectionRef *ref, + char **out_checksum, gsize *out_size, + char **out_collection_id, GError **error) { - g_autoptr(GVariant) additional_metadata = g_variant_get_child_value (pull_data->summary, 1); + g_autoptr (GVariant) additional_metadata = g_variant_get_child_value (pull_data->summary, 1); const gchar *main_collection_id; - if (!g_variant_lookup (additional_metadata, OSTREE_SUMMARY_COLLECTION_ID, "&s", &main_collection_id)) + if (!g_variant_lookup (additional_metadata, OSTREE_SUMMARY_COLLECTION_ID, "&s", + &main_collection_id)) main_collection_id = NULL; - g_autoptr(GVariant) refs = NULL; + g_autoptr (GVariant) refs = NULL; const gchar *resolved_collection_id = NULL; if (ref->collection_id == NULL || g_strcmp0 (ref->collection_id, main_collection_id) == 0) @@ -892,12 +821,13 @@ lookup_commit_checksum_and_collection_from_summary (OtPullData * } else if (ref->collection_id != NULL) { - g_autoptr(GVariant) collection_map = NULL; + g_autoptr (GVariant) collection_map = NULL; collection_map = g_variant_lookup_value (additional_metadata, OSTREE_SUMMARY_COLLECTION_MAP, G_VARIANT_TYPE ("a{sa(s(taya{sv}))}")); if (collection_map != NULL) - refs = g_variant_lookup_value (collection_map, ref->collection_id, G_VARIANT_TYPE ("a(s(taya{sv}))")); + refs = g_variant_lookup_value (collection_map, ref->collection_id, + G_VARIANT_TYPE ("a(s(taya{sv}))")); resolved_collection_id = ref->collection_id; } @@ -905,19 +835,20 @@ lookup_commit_checksum_and_collection_from_summary (OtPullData * if (refs == NULL || !ot_variant_bsearch_str (refs, ref->ref_name, &i)) { if (ref->collection_id != NULL) - return glnx_throw (error, "No such branch (%s, %s) in repository summary", ref->collection_id, ref->ref_name); + return glnx_throw (error, "No such branch (%s, %s) in repository summary", + ref->collection_id, ref->ref_name); else return glnx_throw (error, "No such branch '%s' in repository summary", ref->ref_name); } - g_autoptr(GVariant) refdata = g_variant_get_child_value (refs, i); - g_autoptr(GVariant) reftargetdata = g_variant_get_child_value (refdata, 1); + g_autoptr (GVariant) refdata = g_variant_get_child_value (refs, i); + g_autoptr (GVariant) reftargetdata = g_variant_get_child_value (refdata, 1); guint64 commit_size; - g_autoptr(GVariant) commit_csum_v = NULL; + g_autoptr (GVariant) commit_csum_v = NULL; g_variant_get (reftargetdata, "(t@ay@a{sv})", &commit_size, &commit_csum_v, NULL); - if (resolved_collection_id != NULL && - !ostree_validate_collection_id (resolved_collection_id, error)) + if (resolved_collection_id != NULL + && !ostree_validate_collection_id (resolved_collection_id, error)) return FALSE; if (!ostree_validate_structureof_csum_v (commit_csum_v, error)) return FALSE; @@ -939,13 +870,11 @@ fetch_object_data_free (FetchObjectData *fetch_data) } static void -content_fetch_on_write_complete (GObject *object, - GAsyncResult *result, - gpointer user_data) +content_fetch_on_write_complete (GObject *object, GAsyncResult *result, gpointer user_data) { FetchObjectData *fetch_data = user_data; OtPullData *pull_data = fetch_data->pull_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; OstreeObjectType objtype; const char *expected_checksum; @@ -953,8 +882,7 @@ content_fetch_on_write_complete (GObject *object, g_autofree char *checksum = NULL; g_autofree char *checksum_obj = NULL; - if (!ostree_repo_write_content_finish ((OstreeRepo*)object, result, - &csum, error)) + if (!ostree_repo_write_content_finish ((OstreeRepo *)object, result, &csum, error)) goto out; checksum = ostree_checksum_from_bytes (csum); @@ -972,7 +900,7 @@ content_fetch_on_write_complete (GObject *object, /* Was this a delta fallback? */ if (g_hash_table_remove (pull_data->requested_fallback_content, expected_checksum)) pull_data->n_fetched_deltapart_fallbacks++; - out: +out: pull_data->n_outstanding_content_write_requests--; /* No retries for local writes. */ check_outstanding_requests_handle_error (pull_data, &local_error); @@ -980,23 +908,23 @@ content_fetch_on_write_complete (GObject *object, } static void -content_fetch_on_complete (GObject *object, - GAsyncResult *result, - gpointer user_data) +content_fetch_on_complete (GObject *object, GAsyncResult *result, gpointer user_data) { OstreeFetcher *fetcher = (OstreeFetcher *)object; FetchObjectData *fetch_data = user_data; OtPullData *pull_data = fetch_data->pull_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; GCancellable *cancellable = NULL; guint64 length; - g_auto(GLnxTmpfile) tmpf = { 0, }; - g_autoptr(GInputStream) tmpf_input = NULL; - g_autoptr(GFileInfo) file_info = NULL; - g_autoptr(GVariant) xattrs = NULL; - g_autoptr(GInputStream) file_in = NULL; - g_autoptr(GInputStream) object_input = NULL; + g_auto (GLnxTmpfile) tmpf = { + 0, + }; + g_autoptr (GInputStream) tmpf_input = NULL; + g_autoptr (GFileInfo) file_info = NULL; + g_autoptr (GVariant) xattrs = NULL; + g_autoptr (GInputStream) file_in = NULL; + g_autoptr (GInputStream) object_input = NULL; const char *checksum; g_autofree char *checksum_obj = NULL; OstreeObjectType objtype; @@ -1011,8 +939,8 @@ content_fetch_on_complete (GObject *object, checksum_obj = ostree_object_to_string (checksum, objtype); g_debug ("fetch of %s complete", checksum_obj); - const gboolean verifying_bareuseronly = - (pull_data->importflags & _OSTREE_REPO_IMPORT_FLAGS_VERIFY_BAREUSERONLY) > 0; + const gboolean verifying_bareuseronly + = (pull_data->importflags & _OSTREE_REPO_IMPORT_FLAGS_VERIFY_BAREUSERONLY) > 0; /* See comments where we set this variable; this is implementing * the --trusted-http/OSTREE_REPO_PULL_FLAGS_TRUSTED_HTTP flags. @@ -1020,8 +948,8 @@ content_fetch_on_complete (GObject *object, if (pull_data->trusted_http_direct) { g_assert (!verifying_bareuseronly); - if (!_ostree_repo_commit_tmpf_final (pull_data->repo, checksum, objtype, - &tmpf, cancellable, error)) + if (!_ostree_repo_commit_tmpf_final (pull_data->repo, checksum, objtype, &tmpf, cancellable, + error)) goto out; pull_data->n_fetched_content++; } @@ -1034,9 +962,8 @@ content_fetch_on_complete (GObject *object, tmpf_input = g_unix_input_stream_new (g_steal_fd (&tmpf.fd), TRUE); /* If it appears corrupted, we'll delete it below */ - if (!ostree_content_stream_parse (TRUE, tmpf_input, stbuf.st_size, FALSE, - &file_in, &file_info, &xattrs, - cancellable, error)) + if (!ostree_content_stream_parse (TRUE, tmpf_input, stbuf.st_size, FALSE, &file_in, + &file_info, &xattrs, cancellable, error)) { g_prefix_error (error, "Parsing %s: ", checksum_obj); goto out; @@ -1048,20 +975,17 @@ content_fetch_on_complete (GObject *object, goto out; } - if (!ostree_raw_file_to_content_stream (file_in, file_info, xattrs, - &object_input, &length, + if (!ostree_raw_file_to_content_stream (file_in, file_info, xattrs, &object_input, &length, cancellable, error)) goto out; pull_data->n_outstanding_content_write_requests++; - ostree_repo_write_content_async (pull_data->repo, checksum, - object_input, length, - cancellable, + ostree_repo_write_content_async (pull_data->repo, checksum, object_input, length, cancellable, content_fetch_on_write_complete, fetch_data); free_fetch_data = FALSE; } - out: +out: g_assert (pull_data->n_outstanding_content_fetches > 0); pull_data->n_outstanding_content_fetches--; @@ -1075,13 +999,11 @@ content_fetch_on_complete (GObject *object, } static void -on_metadata_written (GObject *object, - GAsyncResult *result, - gpointer user_data) +on_metadata_written (GObject *object, GAsyncResult *result, gpointer user_data) { FetchObjectData *fetch_data = user_data; OtPullData *pull_data = fetch_data->pull_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; const char *expected_checksum; OstreeObjectType objtype; @@ -1089,8 +1011,7 @@ on_metadata_written (GObject *object, g_autofree guchar *csum = NULL; g_autofree char *stringified_object = NULL; - if (!ostree_repo_write_metadata_finish ((OstreeRepo*)object, result, - &csum, error)) + if (!ostree_repo_write_metadata_finish ((OstreeRepo *)object, result, &csum, error)) goto out; checksum = ostree_checksum_from_bytes (csum); @@ -1109,9 +1030,10 @@ on_metadata_written (GObject *object, goto out; } - queue_scan_one_metadata_object_c (pull_data, csum, objtype, fetch_data->path, 0, fetch_data->requested_ref); + queue_scan_one_metadata_object_c (pull_data, csum, objtype, fetch_data->path, 0, + fetch_data->requested_ref); - out: +out: g_assert (pull_data->n_outstanding_metadata_write_requests > 0); pull_data->n_outstanding_metadata_write_requests--; fetch_object_data_free (fetch_data); @@ -1121,8 +1043,7 @@ on_metadata_written (GObject *object, } static gboolean -is_parent_commit (OtPullData *pull_data, - const char *checksum) +is_parent_commit (OtPullData *pull_data, const char *checksum) { /* FIXME: Only parent commits are added to the commit_to_depth table, * so if the checksum isn't in the table then a new commit chain is @@ -1133,19 +1054,19 @@ is_parent_commit (OtPullData *pull_data, } static void -meta_fetch_on_complete (GObject *object, - GAsyncResult *result, - gpointer user_data) +meta_fetch_on_complete (GObject *object, GAsyncResult *result, gpointer user_data) { OstreeFetcher *fetcher = (OstreeFetcher *)object; FetchObjectData *fetch_data = user_data; OtPullData *pull_data = fetch_data->pull_data; - g_autoptr(GVariant) metadata = NULL; - g_auto(GLnxTmpfile) tmpf = { 0, }; + g_autoptr (GVariant) metadata = NULL; + g_auto (GLnxTmpfile) tmpf = { + 0, + }; const char *checksum; g_autofree char *checksum_obj = NULL; OstreeObjectType objtype; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; gboolean free_fetch_data = TRUE; @@ -1168,9 +1089,11 @@ meta_fetch_on_complete (GObject *object, g_hash_table_insert (pull_data->fetched_detached_metadata, g_strdup (checksum), NULL); if (!fetch_data->object_is_stored) - enqueue_one_object_request (pull_data, checksum, objtype, fetch_data->path, FALSE, FALSE, fetch_data->requested_ref); + enqueue_one_object_request (pull_data, checksum, objtype, fetch_data->path, FALSE, + FALSE, fetch_data->requested_ref); else - queue_scan_one_metadata_object (pull_data, checksum, objtype, fetch_data->path, 0, fetch_data->requested_ref); + queue_scan_one_metadata_object (pull_data, checksum, objtype, fetch_data->path, 0, + fetch_data->requested_ref); } /* When traversing parents, do not fail on a missing commit. @@ -1178,17 +1101,17 @@ meta_fetch_on_complete (GObject *object, * dangling parent reference. This logic should match the * local case in scan_one_metadata_object. */ - else if (objtype == OSTREE_OBJECT_TYPE_COMMIT && - pull_data->maxdepth != 0 && - is_parent_commit (pull_data, checksum)) + else if (objtype == OSTREE_OBJECT_TYPE_COMMIT && pull_data->maxdepth != 0 + && is_parent_commit (pull_data, checksum)) { g_clear_error (&local_error); - /* If the remote repo supports tombstone commits, check if the commit was intentionally - deleted. */ + /* If the remote repo supports tombstone commits, check if the commit was + intentionally deleted. */ if (pull_data->has_tombstone_commits) { - enqueue_one_object_request (pull_data, checksum, OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT, - fetch_data->path, FALSE, FALSE, NULL); + enqueue_one_object_request (pull_data, checksum, + OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT, fetch_data->path, + FALSE, FALSE, NULL); } } } @@ -1202,25 +1125,27 @@ meta_fetch_on_complete (GObject *object, if (fetch_data->is_detached_meta) { - if (!ot_variant_read_fd (tmpf.fd, 0, G_VARIANT_TYPE ("a{sv}"), - FALSE, &metadata, error)) + if (!ot_variant_read_fd (tmpf.fd, 0, G_VARIANT_TYPE ("a{sv}"), FALSE, &metadata, error)) goto out; if (!ostree_repo_write_commit_detached_metadata (pull_data->repo, checksum, metadata, pull_data->cancellable, error)) goto out; - g_hash_table_insert (pull_data->fetched_detached_metadata, g_strdup (checksum), g_steal_pointer (&metadata)); + g_hash_table_insert (pull_data->fetched_detached_metadata, g_strdup (checksum), + g_steal_pointer (&metadata)); if (!fetch_data->object_is_stored) - enqueue_one_object_request (pull_data, checksum, objtype, fetch_data->path, FALSE, FALSE, fetch_data->requested_ref); + enqueue_one_object_request (pull_data, checksum, objtype, fetch_data->path, FALSE, FALSE, + fetch_data->requested_ref); else - queue_scan_one_metadata_object (pull_data, checksum, objtype, fetch_data->path, 0, fetch_data->requested_ref); + queue_scan_one_metadata_object (pull_data, checksum, objtype, fetch_data->path, 0, + fetch_data->requested_ref); } else { - if (!ot_variant_read_fd (tmpf.fd, 0, ostree_metadata_variant_type (objtype), - FALSE, &metadata, error)) + if (!ot_variant_read_fd (tmpf.fd, 0, ostree_metadata_variant_type (objtype), FALSE, &metadata, + error)) goto out; /* Compute checksum and verify structure now. Note this is a recent change @@ -1244,7 +1169,8 @@ meta_fetch_on_complete (GObject *object, * to look up from the disk state as well, or insert the on-disk * metadata into this hash. */ - GVariant *detached_data = g_hash_table_lookup (pull_data->fetched_detached_metadata, checksum); + GVariant *detached_data + = g_hash_table_lookup (pull_data->fetched_detached_metadata, checksum); if (!_verify_unwritten_commit (pull_data, checksum, metadata, detached_data, fetch_data->requested_ref, pull_data->cancellable, error)) goto out; @@ -1260,13 +1186,12 @@ meta_fetch_on_complete (GObject *object, * fetch path does for trusted commits. */ ostree_repo_write_metadata_async (pull_data->repo, objtype, NULL, metadata, - pull_data->cancellable, - on_metadata_written, fetch_data); + pull_data->cancellable, on_metadata_written, fetch_data); pull_data->n_outstanding_metadata_write_requests++; free_fetch_data = FALSE; } - out: +out: g_assert (pull_data->n_outstanding_metadata_fetches > 0); pull_data->n_outstanding_metadata_fetches--; @@ -1283,7 +1208,7 @@ meta_fetch_on_complete (GObject *object, } static void -fetch_static_delta_data_free (gpointer data) +fetch_static_delta_data_free (gpointer data) { FetchStaticDeltaData *fetch_data = data; g_free (fetch_data->expected_checksum); @@ -1294,13 +1219,11 @@ fetch_static_delta_data_free (gpointer data) } static void -on_static_delta_written (GObject *object, - GAsyncResult *result, - gpointer user_data) +on_static_delta_written (GObject *object, GAsyncResult *result, gpointer user_data) { FetchStaticDeltaData *fetch_data = user_data; OtPullData *pull_data = fetch_data->pull_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; g_debug ("execute static delta part %s complete", fetch_data->expected_checksum); @@ -1308,7 +1231,7 @@ on_static_delta_written (GObject *object, if (!_ostree_static_delta_part_execute_finish (pull_data->repo, result, error)) goto out; - out: +out: g_assert (pull_data->n_outstanding_deltapart_write_requests > 0); pull_data->n_outstanding_deltapart_write_requests--; /* No need to retry on failure to write locally. */ @@ -1318,17 +1241,17 @@ on_static_delta_written (GObject *object, } static void -static_deltapart_fetch_on_complete (GObject *object, - GAsyncResult *result, - gpointer user_data) +static_deltapart_fetch_on_complete (GObject *object, GAsyncResult *result, gpointer user_data) { OstreeFetcher *fetcher = (OstreeFetcher *)object; FetchStaticDeltaData *fetch_data = user_data; OtPullData *pull_data = fetch_data->pull_data; - g_auto(GLnxTmpfile) tmpf = { 0, }; - g_autoptr(GInputStream) in = NULL; - g_autoptr(GVariant) part = NULL; - g_autoptr(GError) local_error = NULL; + g_auto (GLnxTmpfile) tmpf = { + 0, + }; + g_autoptr (GInputStream) in = NULL; + g_autoptr (GVariant) part = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; gboolean free_fetch_data = TRUE; @@ -1341,20 +1264,17 @@ static_deltapart_fetch_on_complete (GObject *object, in = g_unix_input_stream_new (g_steal_fd (&tmpf.fd), TRUE); /* TODO - make async */ - if (!_ostree_static_delta_part_open (in, NULL, 0, fetch_data->expected_checksum, - &part, pull_data->cancellable, error)) + if (!_ostree_static_delta_part_open (in, NULL, 0, fetch_data->expected_checksum, &part, + pull_data->cancellable, error)) goto out; - _ostree_static_delta_part_execute_async (pull_data->repo, - fetch_data->objects, - part, - pull_data->cancellable, - on_static_delta_written, + _ostree_static_delta_part_execute_async (pull_data->repo, fetch_data->objects, part, + pull_data->cancellable, on_static_delta_written, fetch_data); pull_data->n_outstanding_deltapart_write_requests++; free_fetch_data = FALSE; - out: +out: g_assert (pull_data->n_outstanding_deltapart_fetches > 0); pull_data->n_outstanding_deltapart_fetches--; @@ -1371,21 +1291,19 @@ static_deltapart_fetch_on_complete (GObject *object, } static gboolean -commitstate_is_partial (OtPullData *pull_data, - OstreeRepoCommitState commitstate) +commitstate_is_partial (OtPullData *pull_data, OstreeRepoCommitState commitstate) { return pull_data->legacy_transaction_resuming - || (commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL) > 0; + || (commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL) > 0; } -#endif /* HAVE_LIBCURL_OR_LIBSOUP */ +#endif /* HAVE_LIBCURL_OR_LIBSOUP */ /* Reads the collection-id of a given remote from the repo * configuration. */ static char * -get_real_remote_repo_collection_id (OstreeRepo *repo, - const gchar *remote_name) +get_real_remote_repo_collection_id (OstreeRepo *repo, const gchar *remote_name) { /* remote_name == NULL can happen for pull-local */ if (!remote_name) @@ -1393,9 +1311,8 @@ get_real_remote_repo_collection_id (OstreeRepo *repo, g_autofree gchar *remote_collection_id = NULL; if (!ostree_repo_get_remote_option (repo, remote_name, "collection-id", NULL, - &remote_collection_id, NULL) || - (remote_collection_id == NULL) || - (remote_collection_id[0] == '\0')) + &remote_collection_id, NULL) + || (remote_collection_id == NULL) || (remote_collection_id[0] == '\0')) return NULL; return g_steal_pointer (&remote_collection_id); @@ -1413,25 +1330,22 @@ get_remote_repo_collection_id (OtPullData *pull_data) { if (pull_data->remote_repo_local != NULL) { - const char *remote_collection_id = - ostree_repo_get_collection_id (pull_data->remote_repo_local); - if ((remote_collection_id == NULL) || - (remote_collection_id[0] == '\0')) + const char *remote_collection_id + = ostree_repo_get_collection_id (pull_data->remote_repo_local); + if ((remote_collection_id == NULL) || (remote_collection_id[0] == '\0')) return NULL; return g_strdup (remote_collection_id); } - return get_real_remote_repo_collection_id (pull_data->repo, - pull_data->remote_name); + return get_real_remote_repo_collection_id (pull_data->repo, pull_data->remote_name); } -#endif /* HAVE_LIBCURL_OR_LIBSOUP */ +#endif /* HAVE_LIBCURL_OR_LIBSOUP */ /* Check whether the given remote exists, has a `collection-id` key set, and it * equals @collection_id. If so, return %TRUE. Otherwise, %FALSE. */ static gboolean -check_remote_matches_collection_id (OstreeRepo *repo, - const gchar *remote_name, +check_remote_matches_collection_id (OstreeRepo *repo, const gchar *remote_name, const gchar *collection_id) { g_autofree gchar *remote_collection_id = NULL; @@ -1466,15 +1380,13 @@ check_remote_matches_collection_id (OstreeRepo *repo, * Since: 2018.6 */ OstreeRemote * -ostree_repo_resolve_keyring_for_collection (OstreeRepo *self, - const gchar *collection_id, - GCancellable *cancellable, - GError **error) +ostree_repo_resolve_keyring_for_collection (OstreeRepo *self, const gchar *collection_id, + GCancellable *cancellable, GError **error) { #ifndef OSTREE_DISABLE_GPGME gsize i; - g_auto(GStrv) remotes = NULL; - g_autoptr(OstreeRemote) keyring_remote = NULL; + g_auto (GStrv) remotes = NULL; + g_autoptr (OstreeRemote) keyring_remote = NULL; g_return_val_if_fail (OSTREE_IS_REPO (self), NULL); g_return_val_if_fail (ostree_validate_collection_id (collection_id, NULL), NULL); @@ -1486,29 +1398,29 @@ ostree_repo_resolve_keyring_for_collection (OstreeRepo *self, for (i = 0; remotes != NULL && remotes[i] != NULL; i++) { - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; if (!check_remote_matches_collection_id (self, remotes[i], collection_id)) continue; if (keyring_remote == NULL) { - g_debug ("%s: Found match for collection ‘%s’ in remote ‘%s’.", - G_STRFUNC, collection_id, remotes[i]); + g_debug ("%s: Found match for collection ‘%s’ in remote ‘%s’.", G_STRFUNC, collection_id, + remotes[i]); keyring_remote = _ostree_repo_get_remote_inherited (self, remotes[i], &local_error); if (keyring_remote == NULL) { - g_debug ("%s: Error loading remote ‘%s’: %s", - G_STRFUNC, remotes[i], local_error->message); + g_debug ("%s: Error loading remote ‘%s’: %s", G_STRFUNC, remotes[i], + local_error->message); continue; } - if (g_strcmp0 (keyring_remote->keyring, "") == 0 || - g_strcmp0 (keyring_remote->keyring, "/dev/null") == 0) + if (g_strcmp0 (keyring_remote->keyring, "") == 0 + || g_strcmp0 (keyring_remote->keyring, "/dev/null") == 0) { - g_debug ("%s: Ignoring remote ‘%s’ as it has no keyring configured.", - G_STRFUNC, remotes[i]); + g_debug ("%s: Ignoring remote ‘%s’ as it has no keyring configured.", G_STRFUNC, + remotes[i]); g_clear_object (&keyring_remote); continue; } @@ -1519,8 +1431,7 @@ ostree_repo_resolve_keyring_for_collection (OstreeRepo *self, { g_debug ("%s: Duplicate keyring for collection ‘%s’ in remote ‘%s’." "Keyring will be loaded from remote ‘%s’.", - G_STRFUNC, collection_id, remotes[i], - keyring_remote->name); + G_STRFUNC, collection_id, remotes[i], keyring_remote->name); } } @@ -1529,14 +1440,12 @@ ostree_repo_resolve_keyring_for_collection (OstreeRepo *self, else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "No keyring found configured locally for collection ‘%s’", - collection_id); + "No keyring found configured locally for collection ‘%s’", collection_id); return NULL; } #else g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "'%s': GPG feature is disabled in a build time", - __FUNCTION__); + "'%s': GPG feature is disabled in a build time", __FUNCTION__); return NULL; #endif /* OSTREE_DISABLE_GPGME */ } @@ -1547,17 +1456,12 @@ ostree_repo_resolve_keyring_for_collection (OstreeRepo *self, * more things to fetch. */ static gboolean -scan_commit_object (OtPullData *pull_data, - const char *checksum, - guint recursion_depth, - const OstreeCollectionRef *ref, - GCancellable *cancellable, - GError **error) +scan_commit_object (OtPullData *pull_data, const char *checksum, guint recursion_depth, + const OstreeCollectionRef *ref, GCancellable *cancellable, GError **error) { gpointer depthp; gint depth; - if (g_hash_table_lookup_extended (pull_data->commit_to_depth, checksum, - NULL, &depthp)) + if (g_hash_table_lookup_extended (pull_data->commit_to_depth, checksum, NULL, &depthp)) { depth = GPOINTER_TO_INT (depthp); } @@ -1570,10 +1474,9 @@ scan_commit_object (OtPullData *pull_data, /* See comment in process_verify_result() - we now gpg check before writing, * but also ensure we've done it here if not already. */ - if (pull_data->gpg_verify && - !g_hash_table_contains (pull_data->verified_commits, checksum)) + if (pull_data->gpg_verify && !g_hash_table_contains (pull_data->verified_commits, checksum)) { - g_autoptr(OstreeGpgVerifyResult) result = NULL; + g_autoptr (OstreeGpgVerifyResult) result = NULL; const char *keyring_remote = NULL; if (ref != NULL) @@ -1581,20 +1484,17 @@ scan_commit_object (OtPullData *pull_data, if (keyring_remote == NULL) keyring_remote = pull_data->remote_name; - result = ostree_repo_verify_commit_for_remote (pull_data->repo, - checksum, - keyring_remote, - cancellable, - error); + result = ostree_repo_verify_commit_for_remote (pull_data->repo, checksum, keyring_remote, + cancellable, error); if (!_process_gpg_verify_result (pull_data, checksum, result, error)) return FALSE; } #endif /* OSTREE_DISABLE_GPGME */ - if (pull_data->signapi_commit_verifiers && - !g_hash_table_contains (pull_data->signapi_verified_commits, checksum)) + if (pull_data->signapi_commit_verifiers + && !g_hash_table_contains (pull_data->signapi_verified_commits, checksum)) { - g_autoptr(GError) last_verification_error = NULL; + g_autoptr (GError) last_verification_error = NULL; gboolean found_any_signature = FALSE; gboolean found_valid_signature = FALSE; g_autofree char *success_message = NULL; @@ -1606,17 +1506,14 @@ scan_commit_object (OtPullData *pull_data, found_any_signature = TRUE; /* Set return to true if any sign fit */ - if (ostree_sign_commit_verify (sign, - pull_data->repo, - checksum, - &success_message, - cancellable, - last_verification_error ? NULL : &last_verification_error)) + if (ostree_sign_commit_verify (sign, pull_data->repo, checksum, &success_message, + cancellable, + last_verification_error ? NULL : &last_verification_error)) { found_valid_signature = TRUE; break; } - } + } if (!found_any_signature) return glnx_throw (error, "No signatures found for commit %s", checksum); @@ -1628,7 +1525,8 @@ scan_commit_object (OtPullData *pull_data, return glnx_prefix_error (error, "Can't verify commit %s", checksum); } g_assert (success_message); - g_hash_table_insert (pull_data->signapi_verified_commits, g_strdup (checksum), g_steal_pointer (&success_message)); + g_hash_table_insert (pull_data->signapi_verified_commits, g_strdup (checksum), + g_steal_pointer (&success_message)); } /* If we found a legacy transaction flag, assume we have to scan. @@ -1636,7 +1534,7 @@ scan_commit_object (OtPullData *pull_data, * https://github.com/ostreedev/ostree/issues/543 */ OstreeRepoCommitState commitstate; - g_autoptr(GVariant) commit = NULL; + g_autoptr (GVariant) commit = NULL; if (!ostree_repo_load_commit (pull_data->repo, checksum, &commit, &commitstate, error)) return FALSE; @@ -1648,8 +1546,7 @@ scan_commit_object (OtPullData *pull_data, */ g_autofree char *remote_collection_id = NULL; remote_collection_id = get_remote_repo_collection_id (pull_data); - if (!_ostree_repo_verify_bindings (remote_collection_id, - (ref != NULL) ? ref->ref_name : NULL, + if (!_ostree_repo_verify_bindings (remote_collection_id, (ref != NULL) ? ref->ref_name : NULL, commit, error)) return glnx_prefix_error (error, "Commit %s", checksum); } @@ -1661,15 +1558,14 @@ scan_commit_object (OtPullData *pull_data, g_assert (ref); g_assert_cmpint (recursion_depth, ==, 0); const char *orig_rev = NULL; - if (!g_hash_table_lookup_extended (pull_data->ref_original_commits, - ref, NULL, (void**)&orig_rev)) + if (!g_hash_table_lookup_extended (pull_data->ref_original_commits, ref, NULL, + (void **)&orig_rev)) g_assert_not_reached (); - g_autoptr(GVariant) orig_commit = NULL; + g_autoptr (GVariant) orig_commit = NULL; if (orig_rev) { - if (!ostree_repo_load_commit (pull_data->repo, orig_rev, - &orig_commit, NULL, error)) + if (!ostree_repo_load_commit (pull_data->repo, orig_rev, &orig_commit, NULL, error)) return glnx_prefix_error (error, "Reading %s for timestamp-check", ref->ref_name); guint64 orig_ts = ostree_commit_get_timestamp (orig_commit); @@ -1679,14 +1575,15 @@ scan_commit_object (OtPullData *pull_data, } if (pull_data->timestamp_check_from_rev) { - g_autoptr(GVariant) timestamp_commit = NULL; + g_autoptr (GVariant) timestamp_commit = NULL; if (!ostree_repo_load_commit (pull_data->repo, pull_data->timestamp_check_from_rev, ×tamp_commit, NULL, error)) return glnx_prefix_error (error, "Reading %s for timestamp-check-from-rev", pull_data->timestamp_check_from_rev); guint64 ts = ostree_commit_get_timestamp (timestamp_commit); - if (!_ostree_compare_timestamps (pull_data->timestamp_check_from_rev, ts, checksum, new_ts, error)) + if (!_ostree_compare_timestamps (pull_data->timestamp_check_from_rev, ts, checksum, new_ts, + error)) return FALSE; } @@ -1694,7 +1591,7 @@ scan_commit_object (OtPullData *pull_data, gboolean is_partial = commitstate_is_partial (pull_data, commitstate); /* PARSE OSTREE_SERIALIZED_COMMIT_VARIANT */ - g_autoptr(GVariant) parent_csum = NULL; + g_autoptr (GVariant) parent_csum = NULL; const guchar *parent_csum_bytes = NULL; g_variant_get_child (commit, 1, "@ay", &parent_csum); if (g_variant_n_children (parent_csum) > 0) @@ -1706,17 +1603,14 @@ scan_commit_object (OtPullData *pull_data, if (parent_csum_bytes != NULL && (pull_data->maxdepth == -1 || depth > 0)) { - char parent_checksum[OSTREE_SHA256_STRING_LEN+1]; + char parent_checksum[OSTREE_SHA256_STRING_LEN + 1]; ostree_checksum_inplace_from_bytes (parent_csum_bytes, parent_checksum); int parent_depth = (depth > 0) ? depth - 1 : -1; g_hash_table_insert (pull_data->commit_to_depth, g_strdup (parent_checksum), GINT_TO_POINTER (parent_depth)); - queue_scan_one_metadata_object_c (pull_data, parent_csum_bytes, - OSTREE_OBJECT_TYPE_COMMIT, - NULL, - recursion_depth + 1, - NULL); + queue_scan_one_metadata_object_c (pull_data, parent_csum_bytes, OSTREE_OBJECT_TYPE_COMMIT, + NULL, recursion_depth + 1, NULL); } /* We only recurse to looking whether we need dirtree/dirmeta @@ -1725,8 +1619,8 @@ scan_commit_object (OtPullData *pull_data, */ if (is_partial && !pull_data->is_commit_only) { - g_autoptr(GVariant) tree_contents_csum = NULL; - g_autoptr(GVariant) tree_meta_csum = NULL; + g_autoptr (GVariant) tree_contents_csum = NULL; + g_autoptr (GVariant) tree_meta_csum = NULL; const guchar *tree_contents_csum_bytes; const guchar *tree_meta_csum_bytes; @@ -1742,21 +1636,20 @@ scan_commit_object (OtPullData *pull_data, return FALSE; queue_scan_one_metadata_object_c (pull_data, tree_contents_csum_bytes, - OSTREE_OBJECT_TYPE_DIR_TREE, "/", recursion_depth + 1, NULL); + OSTREE_OBJECT_TYPE_DIR_TREE, "/", recursion_depth + 1, + NULL); queue_scan_one_metadata_object_c (pull_data, tree_meta_csum_bytes, - OSTREE_OBJECT_TYPE_DIR_META, NULL, recursion_depth + 1, NULL); + OSTREE_OBJECT_TYPE_DIR_META, NULL, recursion_depth + 1, + NULL); } return TRUE; } static void -queue_scan_one_metadata_object (OtPullData *pull_data, - const char *csum, - OstreeObjectType objtype, - const char *path, - guint recursion_depth, +queue_scan_one_metadata_object (OtPullData *pull_data, const char *csum, OstreeObjectType objtype, + const char *path, guint recursion_depth, const OstreeCollectionRef *ref) { guchar buf[OSTREE_SHA256_DIGEST_LEN]; @@ -1765,19 +1658,15 @@ queue_scan_one_metadata_object (OtPullData *pull_data, } static void -queue_scan_one_metadata_object_s (OtPullData *pull_data, - ScanObjectQueueData *scan_data) +queue_scan_one_metadata_object_s (OtPullData *pull_data, ScanObjectQueueData *scan_data) { g_queue_push_tail (&pull_data->scan_object_queue, scan_data); ensure_idle_queued (pull_data); } static void -queue_scan_one_metadata_object_c (OtPullData *pull_data, - const guchar *csum, - OstreeObjectType objtype, - const char *path, - guint recursion_depth, +queue_scan_one_metadata_object_c (OtPullData *pull_data, const guchar *csum, + OstreeObjectType objtype, const char *path, guint recursion_depth, const OstreeCollectionRef *ref) { ScanObjectQueueData *scan_data = g_new0 (ScanObjectQueueData, 1); @@ -1796,16 +1685,11 @@ queue_scan_one_metadata_object_c (OtPullData *pull_data, * execution of this function. */ static gboolean -scan_one_metadata_object (OtPullData *pull_data, - const char *checksum, - OstreeObjectType objtype, - const char *path, - guint recursion_depth, - const OstreeCollectionRef *ref, - GCancellable *cancellable, - GError **error) +scan_one_metadata_object (OtPullData *pull_data, const char *checksum, OstreeObjectType objtype, + const char *path, guint recursion_depth, const OstreeCollectionRef *ref, + GCancellable *cancellable, GError **error) { - g_autoptr(GVariant) object = ostree_object_name_serialize (checksum, objtype); + g_autoptr (GVariant) object = ostree_object_name_serialize (checksum, objtype); /* It may happen that we've already looked at this object (think shared * dirtree subtrees), if that's the case, we're done */ @@ -1815,8 +1699,7 @@ scan_one_metadata_object (OtPullData *pull_data, gboolean is_requested = g_hash_table_lookup (pull_data->requested_metadata, object) != NULL; /* Determine if we already have the object */ gboolean is_stored; - if (!ostree_repo_has_object (pull_data->repo, objtype, checksum, &is_stored, - cancellable, error)) + if (!ostree_repo_has_object (pull_data->repo, objtype, checksum, &is_stored, cancellable, error)) return FALSE; /* Are we pulling an object we don't have from a local repo? */ @@ -1829,10 +1712,9 @@ scan_one_metadata_object (OtPullData *pull_data, return FALSE; } - g_autoptr(GError) local_error = NULL; - if (!_ostree_repo_import_object (pull_data->repo, pull_data->remote_repo_local, - objtype, checksum, pull_data->importflags, - cancellable, &local_error)) + g_autoptr (GError) local_error = NULL; + if (!_ostree_repo_import_object (pull_data->repo, pull_data->remote_repo_local, objtype, + checksum, pull_data->importflags, cancellable, &local_error)) { /* When traversing parents, do not fail on a missing commit. * We may be pulling from a partial repository that ends in a @@ -1841,10 +1723,9 @@ scan_one_metadata_object (OtPullData *pull_data, * * Note early return. */ - if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) && - objtype == OSTREE_OBJECT_TYPE_COMMIT && - pull_data->maxdepth != 0 && - is_parent_commit (pull_data, checksum)) + if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) + && objtype == OSTREE_OBJECT_TYPE_COMMIT && pull_data->maxdepth != 0 + && is_parent_commit (pull_data, checksum)) { g_clear_error (&local_error); @@ -1854,9 +1735,8 @@ scan_one_metadata_object (OtPullData *pull_data, if (pull_data->has_tombstone_commits) { if (!_ostree_repo_import_object (pull_data->repo, pull_data->remote_repo_local, - OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT, - checksum, pull_data->importflags, - cancellable, error)) + OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT, checksum, + pull_data->importflags, cancellable, error)) return FALSE; } @@ -1886,8 +1766,8 @@ scan_one_metadata_object (OtPullData *pull_data, OstreeRepo *refd_repo = pull_data->localcache_repos->pdata[i]; gboolean localcache_repo_has_obj; - if (!ostree_repo_has_object (refd_repo, objtype, checksum, - &localcache_repo_has_obj, cancellable, error)) + if (!ostree_repo_has_object (refd_repo, objtype, checksum, &localcache_repo_has_obj, + cancellable, error)) return FALSE; if (!localcache_repo_has_obj) continue; @@ -1897,9 +1777,8 @@ scan_one_metadata_object (OtPullData *pull_data, if (!ostree_repo_mark_commit_partial (pull_data->repo, checksum, TRUE, error)) return FALSE; } - if (!_ostree_repo_import_object (pull_data->repo, refd_repo, - objtype, checksum, pull_data->importflags, - cancellable, error)) + if (!_ostree_repo_import_object (pull_data->repo, refd_repo, objtype, checksum, + pull_data->importflags, cancellable, error)) return FALSE; /* See comment above */ if (objtype == OSTREE_OBJECT_TYPE_COMMIT) @@ -1918,7 +1797,8 @@ scan_one_metadata_object (OtPullData *pull_data, g_hash_table_add (pull_data->requested_metadata, g_variant_ref (object)); do_fetch_detached = (objtype == OSTREE_OBJECT_TYPE_COMMIT); - enqueue_one_object_request (pull_data, checksum, objtype, path, do_fetch_detached, FALSE, ref); + enqueue_one_object_request (pull_data, checksum, objtype, path, do_fetch_detached, FALSE, + ref); } else if (is_stored && objtype == OSTREE_OBJECT_TYPE_COMMIT) { @@ -1939,8 +1819,8 @@ scan_one_metadata_object (OtPullData *pull_data, } else if (is_stored && objtype == OSTREE_OBJECT_TYPE_DIR_TREE) { - if (!scan_dirtree_object (pull_data, checksum, path, recursion_depth, - pull_data->cancellable, error)) + if (!scan_dirtree_object (pull_data, checksum, path, recursion_depth, pull_data->cancellable, + error)) return glnx_prefix_error (error, "Validating dirtree %s (%s)", checksum, path); g_hash_table_add (pull_data->scanned_metadata, g_variant_ref (object)); @@ -1951,8 +1831,7 @@ scan_one_metadata_object (OtPullData *pull_data, } static void -enqueue_one_object_request_s (OtPullData *pull_data, - FetchObjectData *fetch_data) +enqueue_one_object_request_s (OtPullData *pull_data, FetchObjectData *fetch_data) { const char *checksum; OstreeObjectType objtype; @@ -1963,13 +1842,13 @@ enqueue_one_object_request_s (OtPullData *pull_data, /* Are too many requests are in flight? */ if (fetcher_queue_is_full (pull_data)) { - g_debug ("queuing fetch of %s.%s%s", checksum, - ostree_object_type_to_string (objtype), + g_debug ("queuing fetch of %s.%s%s", checksum, ostree_object_type_to_string (objtype), fetch_data->is_detached_meta ? " (detached)" : ""); if (is_meta) { - g_hash_table_insert (pull_data->pending_fetch_metadata, g_variant_ref (fetch_data->object), fetch_data); + g_hash_table_insert (pull_data->pending_fetch_metadata, + g_variant_ref (fetch_data->object), fetch_data); } else { @@ -1983,12 +1862,8 @@ enqueue_one_object_request_s (OtPullData *pull_data, } static void -enqueue_one_object_request (OtPullData *pull_data, - const char *checksum, - OstreeObjectType objtype, - const char *path, - gboolean is_detached_meta, - gboolean object_is_stored, +enqueue_one_object_request (OtPullData *pull_data, const char *checksum, OstreeObjectType objtype, + const char *path, gboolean is_detached_meta, gboolean object_is_stored, const OstreeCollectionRef *ref) { FetchObjectData *fetch_data; @@ -2011,8 +1886,7 @@ enqueue_one_object_request (OtPullData *pull_data, } static void -start_fetch (OtPullData *pull_data, - FetchObjectData *fetch) +start_fetch (OtPullData *pull_data, FetchObjectData *fetch) { g_autofree char *obj_subpath = NULL; guint64 *expected_max_size_p; @@ -2023,8 +1897,7 @@ start_fetch (OtPullData *pull_data, ostree_object_name_deserialize (fetch->object, &expected_checksum, &objtype); - g_debug ("starting fetch of %s.%s%s", expected_checksum, - ostree_object_type_to_string (objtype), + g_debug ("starting fetch of %s.%s%s", expected_checksum, ostree_object_type_to_string (objtype), fetch->is_detached_meta ? " (detached)" : ""); gboolean is_meta = OSTREE_OBJECT_TYPE_IS_META (objtype); @@ -2038,7 +1911,8 @@ start_fetch (OtPullData *pull_data, if (fetch->is_detached_meta) { char buf[_OSTREE_LOOSE_PATH_MAX]; - _ostree_loose_path (buf, expected_checksum, OSTREE_OBJECT_TYPE_COMMIT_META, pull_data->remote_mode); + _ostree_loose_path (buf, expected_checksum, OSTREE_OBJECT_TYPE_COMMIT_META, + pull_data->remote_mode); obj_subpath = g_build_filename ("objects", buf, NULL); mirrorlist = pull_data->meta_mirrorlist; flags |= OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT; @@ -2052,7 +1926,10 @@ start_fetch (OtPullData *pull_data, /* We may have determined maximum sizes from the summary file content; if so, * honor it. Otherwise, metadata has a baseline max size. */ - expected_max_size_p = fetch->is_detached_meta ? NULL : g_hash_table_lookup (pull_data->expected_commit_sizes, expected_checksum); + expected_max_size_p + = fetch->is_detached_meta + ? NULL + : g_hash_table_lookup (pull_data->expected_commit_sizes, expected_checksum); if (expected_max_size_p) expected_max_size = *expected_max_size_p; else if (OSTREE_OBJECT_TYPE_IS_META (objtype)) @@ -2062,33 +1939,27 @@ start_fetch (OtPullData *pull_data, if (!is_meta && pull_data->trusted_http_direct) flags |= OSTREE_FETCHER_REQUEST_LINKABLE; - _ostree_fetcher_request_to_tmpfile (pull_data->fetcher, mirrorlist, - obj_subpath, flags, NULL, 0, expected_max_size, - is_meta ? OSTREE_REPO_PULL_METADATA_PRIORITY - : OSTREE_REPO_PULL_CONTENT_PRIORITY, - pull_data->cancellable, - is_meta ? meta_fetch_on_complete : content_fetch_on_complete, fetch); + _ostree_fetcher_request_to_tmpfile ( + pull_data->fetcher, mirrorlist, obj_subpath, flags, NULL, 0, expected_max_size, + is_meta ? OSTREE_REPO_PULL_METADATA_PRIORITY : OSTREE_REPO_PULL_CONTENT_PRIORITY, + pull_data->cancellable, is_meta ? meta_fetch_on_complete : content_fetch_on_complete, fetch); } /* Deprecated: code should load options from the `summary` file rather than * downloading the remote’s `config` file, to save on network round trips. */ static gboolean -load_remote_repo_config (OtPullData *pull_data, - GKeyFile **out_keyfile, - GCancellable *cancellable, - GError **error) +load_remote_repo_config (OtPullData *pull_data, GKeyFile **out_keyfile, GCancellable *cancellable, + GError **error) { g_autofree char *contents = NULL; - if (!fetch_mirrored_uri_contents_utf8_sync (pull_data->fetcher, - pull_data->meta_mirrorlist, - "config", pull_data->n_network_retries, - &contents, cancellable, error)) + if (!fetch_mirrored_uri_contents_utf8_sync (pull_data->fetcher, pull_data->meta_mirrorlist, + "config", pull_data->n_network_retries, &contents, + cancellable, error)) return FALSE; - g_autoptr(GKeyFile) ret_keyfile = g_key_file_new (); - if (!g_key_file_load_from_data (ret_keyfile, contents, strlen (contents), - 0, error)) + g_autoptr (GKeyFile) ret_keyfile = g_key_file_new (); + if (!g_key_file_load_from_data (ret_keyfile, contents, strlen (contents), 0, error)) return glnx_prefix_error (error, "Parsing config"); ot_transfer_out_value (out_keyfile, &ret_keyfile); @@ -2096,18 +1967,16 @@ load_remote_repo_config (OtPullData *pull_data, } static gboolean -process_one_static_delta_fallback (OtPullData *pull_data, - gboolean delta_byteswap, - GVariant *fallback_object, - GCancellable *cancellable, - GError **error) +process_one_static_delta_fallback (OtPullData *pull_data, gboolean delta_byteswap, + GVariant *fallback_object, GCancellable *cancellable, + GError **error) { guint8 objtype_y; - g_autoptr(GVariant) csum_v = NULL; + g_autoptr (GVariant) csum_v = NULL; guint64 compressed_size, uncompressed_size; - g_variant_get (fallback_object, "(y@aytt)", - &objtype_y, &csum_v, &compressed_size, &uncompressed_size); + g_variant_get (fallback_object, "(y@aytt)", &objtype_y, &csum_v, &compressed_size, + &uncompressed_size); if (!ostree_validate_structureof_objtype (objtype_y, error)) return FALSE; @@ -2125,9 +1994,7 @@ process_one_static_delta_fallback (OtPullData *pull_data, g_autofree char *checksum = ostree_checksum_from_bytes_v (csum_v); gboolean is_stored; - if (!ostree_repo_has_object (pull_data->repo, objtype, checksum, - &is_stored, - cancellable, error)) + if (!ostree_repo_has_object (pull_data->repo, objtype, checksum, &is_stored, cancellable, error)) return FALSE; if (is_stored) @@ -2152,8 +2019,9 @@ process_one_static_delta_fallback (OtPullData *pull_data, * for it as logically part of the delta fetch. */ g_hash_table_add (pull_data->requested_fallback_content, g_strdup (checksum)); - enqueue_one_object_request (pull_data, checksum, OSTREE_OBJECT_TYPE_FILE, NULL, FALSE, FALSE, NULL); - checksum = NULL; /* We transferred ownership to the requested_content hash */ + enqueue_one_object_request (pull_data, checksum, OSTREE_OBJECT_TYPE_FILE, NULL, FALSE, + FALSE, NULL); + checksum = NULL; /* We transferred ownership to the requested_content hash */ } } } @@ -2162,13 +2030,11 @@ process_one_static_delta_fallback (OtPullData *pull_data, } static void -enqueue_one_static_delta_part_request_s (OtPullData *pull_data, - FetchStaticDeltaData *fetch_data) +enqueue_one_static_delta_part_request_s (OtPullData *pull_data, FetchStaticDeltaData *fetch_data) { if (fetcher_queue_is_full (pull_data)) { - g_debug ("queuing fetch of static delta %s-%s part %u", - fetch_data->from_revision ?: "empty", + g_debug ("queuing fetch of static delta %s-%s part %u", fetch_data->from_revision ?: "empty", fetch_data->to_revision, fetch_data->i); g_hash_table_add (pull_data->pending_fetch_deltaparts, fetch_data); @@ -2180,37 +2046,31 @@ enqueue_one_static_delta_part_request_s (OtPullData *pull_data, } static void -start_fetch_deltapart (OtPullData *pull_data, - FetchStaticDeltaData *fetch) +start_fetch_deltapart (OtPullData *pull_data, FetchStaticDeltaData *fetch) { - g_autofree char *deltapart_path = _ostree_get_relative_static_delta_part_path (fetch->from_revision, fetch->to_revision, fetch->i); + g_autofree char *deltapart_path = _ostree_get_relative_static_delta_part_path ( + fetch->from_revision, fetch->to_revision, fetch->i); g_debug ("starting fetch of deltapart %s", deltapart_path); pull_data->n_outstanding_deltapart_fetches++; - g_assert_cmpint (pull_data->n_outstanding_deltapart_fetches, <=, _OSTREE_MAX_OUTSTANDING_DELTAPART_REQUESTS); - _ostree_fetcher_request_to_tmpfile (pull_data->fetcher, - pull_data->content_mirrorlist, + g_assert_cmpint (pull_data->n_outstanding_deltapart_fetches, <=, + _OSTREE_MAX_OUTSTANDING_DELTAPART_REQUESTS); + _ostree_fetcher_request_to_tmpfile (pull_data->fetcher, pull_data->content_mirrorlist, deltapart_path, 0, NULL, 0, fetch->size, - OSTREE_FETCHER_DEFAULT_PRIORITY, - pull_data->cancellable, - static_deltapart_fetch_on_complete, - fetch); + OSTREE_FETCHER_DEFAULT_PRIORITY, pull_data->cancellable, + static_deltapart_fetch_on_complete, fetch); } static gboolean -process_one_static_delta (OtPullData *pull_data, - const char *from_revision, - const char *to_revision, - GVariant *delta_superblock, - const OstreeCollectionRef *ref, - GCancellable *cancellable, - GError **error) +process_one_static_delta (OtPullData *pull_data, const char *from_revision, const char *to_revision, + GVariant *delta_superblock, const OstreeCollectionRef *ref, + GCancellable *cancellable, GError **error) { gboolean delta_byteswap = _ostree_delta_needs_byteswap (delta_superblock); /* Parsing OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT */ - g_autoptr(GVariant) metadata = g_variant_get_child_value (delta_superblock, 0); - g_autoptr(GVariant) headers = g_variant_get_child_value (delta_superblock, 6); - g_autoptr(GVariant) fallback_objects = g_variant_get_child_value (delta_superblock, 7); + g_autoptr (GVariant) metadata = g_variant_get_child_value (delta_superblock, 0); + g_autoptr (GVariant) headers = g_variant_get_child_value (delta_superblock, 6); + g_autoptr (GVariant) fallback_objects = g_variant_get_child_value (delta_superblock, 7); /* Gather free space so we can do a check below */ struct statvfs stvfsbuf; @@ -2221,11 +2081,9 @@ process_one_static_delta (OtPullData *pull_data, guint n = g_variant_n_children (fallback_objects); for (guint i = 0; i < n; i++) { - g_autoptr(GVariant) fallback_object = - g_variant_get_child_value (fallback_objects, i); + g_autoptr (GVariant) fallback_object = g_variant_get_child_value (fallback_objects, i); - if (!process_one_static_delta_fallback (pull_data, delta_byteswap, - fallback_object, + if (!process_one_static_delta_fallback (pull_data, delta_byteswap, fallback_object, cancellable, error)) return FALSE; } @@ -2233,7 +2091,7 @@ process_one_static_delta (OtPullData *pull_data, /* Write the to-commit object */ if (!pull_data->dry_run) { - g_autoptr(GVariant) to_csum_v = g_variant_get_child_value (delta_superblock, 3); + g_autoptr (GVariant) to_csum_v = g_variant_get_child_value (delta_superblock, 3); if (!ostree_validate_structureof_csum_v (to_csum_v, error)) return FALSE; g_autofree char *to_checksum = ostree_checksum_from_bytes_v (to_csum_v); @@ -2245,36 +2103,36 @@ process_one_static_delta (OtPullData *pull_data, if (!have_to_commit) { - g_autoptr(GVariant) to_commit = g_variant_get_child_value (delta_superblock, 4); - g_autofree char *detached_path = _ostree_get_relative_static_delta_path (from_revision, to_revision, "commitmeta"); - g_autoptr(GVariant) detached_data = g_variant_lookup_value (metadata, detached_path, G_VARIANT_TYPE("a{sv}")); + g_autoptr (GVariant) to_commit = g_variant_get_child_value (delta_superblock, 4); + g_autofree char *detached_path + = _ostree_get_relative_static_delta_path (from_revision, to_revision, "commitmeta"); + g_autoptr (GVariant) detached_data + = g_variant_lookup_value (metadata, detached_path, G_VARIANT_TYPE ("a{sv}")); - if (!_verify_unwritten_commit (pull_data, to_revision, to_commit, detached_data, - ref, cancellable, error)) + if (!_verify_unwritten_commit (pull_data, to_revision, to_commit, detached_data, ref, + cancellable, error)) return FALSE; if (!ostree_repo_mark_commit_partial (pull_data->repo, to_revision, TRUE, error)) return FALSE; - if (detached_data && !ostree_repo_write_commit_detached_metadata (pull_data->repo, - to_revision, - detached_data, - cancellable, - error)) + if (detached_data + && !ostree_repo_write_commit_detached_metadata (pull_data->repo, to_revision, + detached_data, cancellable, error)) return FALSE; FetchObjectData *fetch_data = g_new0 (FetchObjectData, 1); fetch_data->pull_data = pull_data; - fetch_data->object = ostree_object_name_serialize (to_checksum, OSTREE_OBJECT_TYPE_COMMIT); + fetch_data->object + = ostree_object_name_serialize (to_checksum, OSTREE_OBJECT_TYPE_COMMIT); fetch_data->is_detached_meta = FALSE; fetch_data->object_is_stored = FALSE; fetch_data->requested_ref = (ref != NULL) ? ostree_collection_ref_dup (ref) : NULL; fetch_data->n_retries_remaining = pull_data->n_network_retries; ostree_repo_write_metadata_async (pull_data->repo, OSTREE_OBJECT_TYPE_COMMIT, to_checksum, - to_commit, - pull_data->cancellable, - on_metadata_written, fetch_data); + to_commit, pull_data->cancellable, on_metadata_written, + fetch_data); pull_data->n_outstanding_metadata_write_requests++; } } @@ -2286,10 +2144,10 @@ process_one_static_delta (OtPullData *pull_data, { gboolean have_all = FALSE; - g_autoptr(GVariant) header = g_variant_get_child_value (headers, i); - g_autoptr(GVariant) csum_v = NULL; - g_autoptr(GVariant) objects = NULL; - g_autoptr(GBytes) inline_part_bytes = NULL; + g_autoptr (GVariant) header = g_variant_get_child_value (headers, i); + g_autoptr (GVariant) csum_v = NULL; + g_autoptr (GVariant) objects = NULL; + g_autoptr (GBytes) inline_part_bytes = NULL; guint32 version; guint64 size, usize; g_variant_get (header, "(u@aytt@ay)", &version, &csum_v, &size, &usize, &objects); @@ -2304,9 +2162,7 @@ process_one_static_delta (OtPullData *pull_data, if (!csum) return FALSE; - if (!_ostree_repo_static_delta_part_have_all_objects (pull_data->repo, - objects, - &have_all, + if (!_ostree_repo_static_delta_part_have_all_objects (pull_data->repo, objects, &have_all, cancellable, error)) return FALSE; @@ -2315,18 +2171,19 @@ process_one_static_delta (OtPullData *pull_data, if (have_all) { - g_debug ("Have all objects from static delta %s-%s part %u", - from_revision ?: "empty", to_revision, - i); + g_debug ("Have all objects from static delta %s-%s part %u", from_revision ?: "empty", + to_revision, i); pull_data->fetched_deltapart_size += size; pull_data->n_fetched_deltaparts++; continue; } - g_autofree char *deltapart_path = _ostree_get_relative_static_delta_part_path (from_revision, to_revision, i); + g_autofree char *deltapart_path + = _ostree_get_relative_static_delta_part_path (from_revision, to_revision, i); - { g_autoptr(GVariant) part_datav = - g_variant_lookup_value (metadata, deltapart_path, G_VARIANT_TYPE ("(yay)")); + { + g_autoptr (GVariant) part_datav + = g_variant_lookup_value (metadata, deltapart_path, G_VARIANT_TYPE ("(yay)")); if (part_datav) inline_part_bytes = g_variant_get_data_as_bytes (part_datav); @@ -2347,25 +2204,21 @@ process_one_static_delta (OtPullData *pull_data, if (inline_part_bytes != NULL) { - g_autoptr(GInputStream) memin = g_memory_input_stream_new_from_bytes (inline_part_bytes); - g_autoptr(GVariant) inline_delta_part = NULL; + g_autoptr (GInputStream) memin = g_memory_input_stream_new_from_bytes (inline_part_bytes); + g_autoptr (GVariant) inline_delta_part = NULL; /* For inline parts we are relying on per-commit GPG, so don't bother checksumming. */ if (!_ostree_static_delta_part_open (memin, inline_part_bytes, - OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM, - NULL, &inline_delta_part, - cancellable, error)) + OSTREE_STATIC_DELTA_OPEN_FLAGS_SKIP_CHECKSUM, NULL, + &inline_delta_part, cancellable, error)) { fetch_static_delta_data_free (fetch_data); return FALSE; } - _ostree_static_delta_part_execute_async (pull_data->repo, - fetch_data->objects, - inline_delta_part, - pull_data->cancellable, - on_static_delta_written, - fetch_data); + _ostree_static_delta_part_execute_async (pull_data->repo, fetch_data->objects, + inline_delta_part, pull_data->cancellable, + on_static_delta_written, fetch_data); pull_data->n_outstanding_deltapart_write_requests++; } else @@ -2383,7 +2236,8 @@ process_one_static_delta (OtPullData *pull_data, if (delta_required_blocks > stvfsbuf.f_bfree) { g_autofree char *formatted_required = g_format_size (pull_data->total_deltapart_usize); - g_autofree char *formatted_avail = g_format_size (((guint64)stvfsbuf.f_bsize) * stvfsbuf.f_bfree); + g_autofree char *formatted_avail + = g_format_size (((guint64)stvfsbuf.f_bsize) * stvfsbuf.f_bfree); return glnx_throw (error, "Delta requires %s free space, but only %s available", formatted_required, formatted_avail); } @@ -2406,14 +2260,16 @@ process_one_static_delta (OtPullData *pull_data, * There is a %NULL → @to_revision delta, also known as * a "from scratch" delta. */ -typedef struct { - enum { +typedef struct +{ + enum + { DELTA_SEARCH_RESULT_UNCHANGED, DELTA_SEARCH_RESULT_NO_MATCH, DELTA_SEARCH_RESULT_FROM, DELTA_SEARCH_RESULT_SCRATCH, } result; - char from_revision[OSTREE_SHA256_STRING_LEN+1]; + char from_revision[OSTREE_SHA256_STRING_LEN + 1]; } DeltaSearchResult; /* Loop over the static delta data we got from the summary, @@ -2421,14 +2277,12 @@ typedef struct { * See the enum in `DeltaSearchResult` for available result types. */ static gboolean -get_best_static_delta_start_for (OtPullData *pull_data, - const char *to_revision, - DeltaSearchResult *out_result, - GCancellable *cancellable, - GError **error) +get_best_static_delta_start_for (OtPullData *pull_data, const char *to_revision, + DeltaSearchResult *out_result, GCancellable *cancellable, + GError **error) { /* Array<char*> of possible from checksums */ - g_autoptr(GPtrArray) candidates = g_ptr_array_new_with_free_func (g_free); + g_autoptr (GPtrArray) candidates = g_ptr_array_new_with_free_func (g_free); const char *newest_candidate = NULL; guint64 newest_candidate_timestamp = 0; @@ -2439,27 +2293,25 @@ get_best_static_delta_start_for (OtPullData *pull_data, /* First, do we already have this commit completely downloaded? */ gboolean have_to_rev; - if (!ostree_repo_has_object (pull_data->repo, OSTREE_OBJECT_TYPE_COMMIT, - to_revision, &have_to_rev, - cancellable, error)) + if (!ostree_repo_has_object (pull_data->repo, OSTREE_OBJECT_TYPE_COMMIT, to_revision, + &have_to_rev, cancellable, error)) return FALSE; if (have_to_rev) { OstreeRepoCommitState to_rev_state; - if (!ostree_repo_load_commit (pull_data->repo, to_revision, - NULL, &to_rev_state, error)) + if (!ostree_repo_load_commit (pull_data->repo, to_revision, NULL, &to_rev_state, error)) return FALSE; - if (!(commitstate_is_partial(pull_data, to_rev_state))) + if (!(commitstate_is_partial (pull_data, to_rev_state))) { /* We already have this commit, we're done! */ out_result->result = DELTA_SEARCH_RESULT_UNCHANGED; - return TRUE; /* Early return */ + return TRUE; /* Early return */ } } /* Loop over all deltas known from the summary file, * finding ones which go to to_revision */ - GLNX_HASH_TABLE_FOREACH (pull_data->summary_deltas_checksums, const char*, delta_name) + GLNX_HASH_TABLE_FOREACH (pull_data->summary_deltas_checksums, const char *, delta_name) { g_autofree char *cur_from_rev = NULL; g_autofree char *cur_to_rev = NULL; @@ -2491,21 +2343,19 @@ get_best_static_delta_start_for (OtPullData *pull_data, { const char *candidate = candidates->pdata[i]; guint64 candidate_ts = 0; - g_autoptr(GVariant) commit = NULL; + g_autoptr (GVariant) commit = NULL; OstreeRepoCommitState state; gboolean have_candidate; /* Do we have this commit at all? If not, skip it */ - if (!ostree_repo_has_object (pull_data->repo, OSTREE_OBJECT_TYPE_COMMIT, - candidate, &have_candidate, - NULL, error)) + if (!ostree_repo_has_object (pull_data->repo, OSTREE_OBJECT_TYPE_COMMIT, candidate, + &have_candidate, NULL, error)) return FALSE; if (!have_candidate) continue; /* Load it */ - if (!ostree_repo_load_commit (pull_data->repo, candidate, - &commit, &state, error)) + if (!ostree_repo_load_commit (pull_data->repo, candidate, &commit, &state, error)) return FALSE; /* Ignore partial commits, we can't use them */ @@ -2514,8 +2364,7 @@ get_best_static_delta_start_for (OtPullData *pull_data, /* Is it newer? */ candidate_ts = ostree_commit_get_timestamp (commit); - if (newest_candidate == NULL || - candidate_ts > newest_candidate_timestamp) + if (newest_candidate == NULL || candidate_ts > newest_candidate_timestamp) { newest_candidate = candidate; newest_candidate_timestamp = candidate_ts; @@ -2525,7 +2374,7 @@ get_best_static_delta_start_for (OtPullData *pull_data, if (newest_candidate) { out_result->result = DELTA_SEARCH_RESULT_FROM; - memcpy (out_result->from_revision, newest_candidate, OSTREE_SHA256_STRING_LEN+1); + memcpy (out_result->from_revision, newest_candidate, OSTREE_SHA256_STRING_LEN + 1); } return TRUE; } @@ -2551,34 +2400,26 @@ fetch_delta_index_data_free (FetchDeltaIndexData *fetch_data) } static void -set_required_deltas_error (GError **error, - const char *from_revision, - const char *to_revision) +set_required_deltas_error (GError **error, const char *from_revision, const char *to_revision) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Static deltas required, but none found for %s to %s", - from_revision, to_revision); + "Static deltas required, but none found for %s to %s", from_revision, to_revision); } static void -on_superblock_fetched (GObject *src, - GAsyncResult *res, - gpointer data) +on_superblock_fetched (GObject *src, GAsyncResult *res, gpointer data) { FetchDeltaSuperData *fetch_data = data; OtPullData *pull_data = fetch_data->pull_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; - g_autoptr(GBytes) delta_superblock_data = NULL; + g_autoptr (GBytes) delta_superblock_data = NULL; const char *from_revision = fetch_data->from_revision; const char *to_revision = fetch_data->to_revision; - if (!_ostree_fetcher_request_to_membuf_finish ((OstreeFetcher*)src, - res, - &delta_superblock_data, - NULL, NULL, NULL, - error)) + if (!_ostree_fetcher_request_to_membuf_finish ((OstreeFetcher *)src, res, &delta_superblock_data, + NULL, NULL, NULL, error)) { if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) goto out; @@ -2590,13 +2431,16 @@ on_superblock_fetched (GObject *src, goto out; } - queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, fetch_data->requested_ref); + queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, + fetch_data->requested_ref); } else { - g_autoptr(GVariant) delta_superblock = NULL; - g_autofree gchar *delta = g_strconcat (from_revision ?: "", from_revision ? "-" : "", to_revision, NULL); - const guchar *expected_summary_digest = g_hash_table_lookup (pull_data->summary_deltas_checksums, delta); + g_autoptr (GVariant) delta_superblock = NULL; + g_autofree gchar *delta + = g_strconcat (from_revision ?: "", from_revision ? "-" : "", to_revision, NULL); + const guchar *expected_summary_digest + = g_hash_table_lookup (pull_data->summary_deltas_checksums, delta); guint8 actual_summary_digest[OSTREE_SHA256_DIGEST_LEN]; ot_checksum_bytes (delta_superblock_data, actual_summary_digest); @@ -2609,27 +2453,31 @@ on_superblock_fetched (GObject *src, if (pull_data->gpg_verify_summary && !expected_summary_digest) { g_set_error (error, OSTREE_GPG_ERROR, OSTREE_GPG_ERROR_NO_SIGNATURE, - "GPG verification enabled, but no summary signatures found (use gpg-verify-summary=false in remote config to disable)"); + "GPG verification enabled, but no summary signatures found (use " + "gpg-verify-summary=false in remote config to disable)"); goto out; } #endif /* OSTREE_DISABLE_GPGME */ - if (expected_summary_digest && memcmp (expected_summary_digest, actual_summary_digest, sizeof (actual_summary_digest))) + if (expected_summary_digest + && memcmp (expected_summary_digest, actual_summary_digest, + sizeof (actual_summary_digest))) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid checksum for static delta %s", delta); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid checksum for static delta %s", + delta); goto out; } - delta_superblock = g_variant_ref_sink (g_variant_new_from_bytes ((GVariantType*)OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT, - delta_superblock_data, FALSE)); + delta_superblock = g_variant_ref_sink (g_variant_new_from_bytes ( + (GVariantType *)OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT, delta_superblock_data, FALSE)); g_ptr_array_add (pull_data->static_delta_superblocks, g_variant_ref (delta_superblock)); - if (!process_one_static_delta (pull_data, from_revision, to_revision, delta_superblock, fetch_data->requested_ref, - pull_data->cancellable, error)) + if (!process_one_static_delta (pull_data, from_revision, to_revision, delta_superblock, + fetch_data->requested_ref, pull_data->cancellable, error)) goto out; } - out: +out: g_assert (pull_data->n_outstanding_metadata_fetches > 0); pull_data->n_outstanding_metadata_fetches--; @@ -2645,37 +2493,29 @@ on_superblock_fetched (GObject *src, } static void -start_fetch_delta_superblock (OtPullData *pull_data, - FetchDeltaSuperData *fetch_data) +start_fetch_delta_superblock (OtPullData *pull_data, FetchDeltaSuperData *fetch_data) { - g_autofree char *delta_name = - _ostree_get_relative_static_delta_superblock_path (fetch_data->from_revision, - fetch_data->to_revision); + g_autofree char *delta_name = _ostree_get_relative_static_delta_superblock_path ( + fetch_data->from_revision, fetch_data->to_revision); g_debug ("starting fetch of delta superblock %s", delta_name); - _ostree_fetcher_request_to_membuf (pull_data->fetcher, - pull_data->content_mirrorlist, - delta_name, OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - NULL, 0, - OSTREE_MAX_METADATA_SIZE, - 0, pull_data->cancellable, - on_superblock_fetched, - g_steal_pointer (&fetch_data)); + _ostree_fetcher_request_to_membuf (pull_data->fetcher, pull_data->content_mirrorlist, delta_name, + OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, NULL, 0, + OSTREE_MAX_METADATA_SIZE, 0, pull_data->cancellable, + on_superblock_fetched, g_steal_pointer (&fetch_data)); pull_data->n_outstanding_metadata_fetches++; pull_data->n_requested_metadata++; } static void -enqueue_one_static_delta_superblock_request_s (OtPullData *pull_data, +enqueue_one_static_delta_superblock_request_s (OtPullData *pull_data, FetchDeltaSuperData *fetch_data) { if (fetcher_queue_is_full (pull_data)) { g_debug ("queuing fetch of static delta superblock %s-%s", - fetch_data->from_revision ?: "empty", - fetch_data->to_revision); + fetch_data->from_revision ?: "empty", fetch_data->to_revision); - g_hash_table_add (pull_data->pending_fetch_delta_superblocks, - g_steal_pointer (&fetch_data)); + g_hash_table_add (pull_data->pending_fetch_delta_superblocks, g_steal_pointer (&fetch_data)); } else { @@ -2685,12 +2525,11 @@ enqueue_one_static_delta_superblock_request_s (OtPullData *pull_data, /* Start a request for a static delta */ static void -enqueue_one_static_delta_superblock_request (OtPullData *pull_data, - const char *from_revision, - const char *to_revision, +enqueue_one_static_delta_superblock_request (OtPullData *pull_data, const char *from_revision, + const char *to_revision, const OstreeCollectionRef *ref) { - FetchDeltaSuperData *fdata = g_new0(FetchDeltaSuperData, 1); + FetchDeltaSuperData *fdata = g_new0 (FetchDeltaSuperData, 1); fdata->pull_data = pull_data; fdata->from_revision = g_strdup (from_revision); fdata->to_revision = g_strdup (to_revision); @@ -2701,8 +2540,7 @@ enqueue_one_static_delta_superblock_request (OtPullData *pull_dat } static gboolean -validate_variant_is_csum (GVariant *csum, - GError **error) +validate_variant_is_csum (GVariant *csum, GError **error) { if (!g_variant_is_of_type (csum, G_VARIANT_TYPE ("ay"))) return glnx_throw (error, "Invalid checksum variant of type '%s', expected 'ay'", @@ -2712,9 +2550,7 @@ validate_variant_is_csum (GVariant *csum, } static gboolean -collect_available_deltas_for_pull (OtPullData *pull_data, - GVariant *deltas, - GError **error) +collect_available_deltas_for_pull (OtPullData *pull_data, GVariant *deltas, GError **error) { gsize n; @@ -2722,8 +2558,8 @@ collect_available_deltas_for_pull (OtPullData *pull_data, for (gsize i = 0; i < n; i++) { const char *delta; - g_autoptr(GVariant) csum_v = NULL; - g_autoptr(GVariant) ref = g_variant_get_child_value (deltas, i); + g_autoptr (GVariant) csum_v = NULL; + g_autoptr (GVariant) ref = g_variant_get_child_value (deltas, i); g_variant_get_child (ref, 0, "&s", &delta); g_variant_get_child (ref, 1, "v", &csum_v); @@ -2733,57 +2569,50 @@ collect_available_deltas_for_pull (OtPullData *pull_data, guchar *csum_data = g_malloc (OSTREE_SHA256_DIGEST_LEN); memcpy (csum_data, ostree_checksum_bytes_peek (csum_v), 32); - g_hash_table_insert (pull_data->summary_deltas_checksums, - g_strdup (delta), - csum_data); + g_hash_table_insert (pull_data->summary_deltas_checksums, g_strdup (delta), csum_data); } return TRUE; } static void -on_delta_index_fetched (GObject *src, - GAsyncResult *res, - gpointer data) +on_delta_index_fetched (GObject *src, GAsyncResult *res, gpointer data) { FetchDeltaIndexData *fetch_data = data; OtPullData *pull_data = fetch_data->pull_data; - g_autoptr(GError) local_error = NULL; + g_autoptr (GError) local_error = NULL; GError **error = &local_error; - g_autoptr(GBytes) delta_index_data = NULL; + g_autoptr (GBytes) delta_index_data = NULL; const char *from_revision = fetch_data->from_revision; const char *to_revision = fetch_data->to_revision; - if (!_ostree_fetcher_request_to_membuf_finish ((OstreeFetcher*)src, - res, - &delta_index_data, - NULL, NULL, NULL, - error)) + if (!_ostree_fetcher_request_to_membuf_finish ((OstreeFetcher *)src, res, &delta_index_data, NULL, + NULL, NULL, error)) { if (!g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) goto out; g_clear_error (&local_error); - /* below call to initiate_delta_request() will fail finding the delta and fall back to commit */ + /* below call to initiate_delta_request() will fail finding the delta and fall back to commit + */ } else { - g_autoptr(GVariant) delta_index = g_variant_ref_sink (g_variant_new_from_bytes (G_VARIANT_TYPE_VARDICT, delta_index_data, FALSE)); - g_autoptr(GVariant) deltas = g_variant_lookup_value (delta_index, OSTREE_SUMMARY_STATIC_DELTAS, G_VARIANT_TYPE ("a{sv}")); + g_autoptr (GVariant) delta_index = g_variant_ref_sink ( + g_variant_new_from_bytes (G_VARIANT_TYPE_VARDICT, delta_index_data, FALSE)); + g_autoptr (GVariant) deltas = g_variant_lookup_value ( + delta_index, OSTREE_SUMMARY_STATIC_DELTAS, G_VARIANT_TYPE ("a{sv}")); if (!collect_available_deltas_for_pull (pull_data, deltas, error)) goto out; } - if (!initiate_delta_request (pull_data, - fetch_data->requested_ref, - to_revision, - from_revision, + if (!initiate_delta_request (pull_data, fetch_data->requested_ref, to_revision, from_revision, &local_error)) goto out; - out: +out: g_assert (pull_data->n_outstanding_metadata_fetches > 0); pull_data->n_outstanding_metadata_fetches--; @@ -2799,35 +2628,27 @@ on_delta_index_fetched (GObject *src, } static void -start_fetch_delta_index (OtPullData *pull_data, - FetchDeltaIndexData *fetch_data) +start_fetch_delta_index (OtPullData *pull_data, FetchDeltaIndexData *fetch_data) { - g_autofree char *delta_name = - _ostree_get_relative_static_delta_index_path (fetch_data->to_revision); + g_autofree char *delta_name + = _ostree_get_relative_static_delta_index_path (fetch_data->to_revision); g_debug ("starting fetch of delta index %s", delta_name); - _ostree_fetcher_request_to_membuf (pull_data->fetcher, - pull_data->content_mirrorlist, - delta_name, OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - NULL, 0, - OSTREE_MAX_METADATA_SIZE, - 0, pull_data->cancellable, - on_delta_index_fetched, - g_steal_pointer (&fetch_data)); + _ostree_fetcher_request_to_membuf (pull_data->fetcher, pull_data->content_mirrorlist, delta_name, + OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, NULL, 0, + OSTREE_MAX_METADATA_SIZE, 0, pull_data->cancellable, + on_delta_index_fetched, g_steal_pointer (&fetch_data)); pull_data->n_outstanding_metadata_fetches++; pull_data->n_requested_metadata++; } static void -enqueue_one_static_delta_index_request_s (OtPullData *pull_data, - FetchDeltaIndexData *fetch_data) +enqueue_one_static_delta_index_request_s (OtPullData *pull_data, FetchDeltaIndexData *fetch_data) { if (fetcher_queue_is_full (pull_data)) { - g_debug ("queuing fetch of static delta index to %s", - fetch_data->to_revision); + g_debug ("queuing fetch of static delta index to %s", fetch_data->to_revision); - g_hash_table_add (pull_data->pending_fetch_delta_indexes, - g_steal_pointer (&fetch_data)); + g_hash_table_add (pull_data->pending_fetch_delta_indexes, g_steal_pointer (&fetch_data)); } else { @@ -2837,12 +2658,10 @@ enqueue_one_static_delta_index_request_s (OtPullData *pull_data, /* Start a request for a static delta index */ static void -enqueue_one_static_delta_index_request (OtPullData *pull_data, - const char *to_revision, - const char *from_revision, - const OstreeCollectionRef *ref) +enqueue_one_static_delta_index_request (OtPullData *pull_data, const char *to_revision, + const char *from_revision, const OstreeCollectionRef *ref) { - FetchDeltaIndexData *fdata = g_new0(FetchDeltaIndexData, 1); + FetchDeltaIndexData *fdata = g_new0 (FetchDeltaIndexData, 1); fdata->pull_data = pull_data; fdata->from_revision = g_strdup (from_revision); fdata->to_revision = g_strdup (to_revision); @@ -2853,42 +2672,34 @@ enqueue_one_static_delta_index_request (OtPullData *pull_data, } static gboolean -_ostree_repo_verify_summary (OstreeRepo *self, - const char *name, - gboolean gpg_verify_summary, - GPtrArray *signapi_summary_verifiers, - GBytes *summary, - GBytes *signatures, - GCancellable *cancellable, - GError **error) +_ostree_repo_verify_summary (OstreeRepo *self, const char *name, gboolean gpg_verify_summary, + GPtrArray *signapi_summary_verifiers, GBytes *summary, + GBytes *signatures, GCancellable *cancellable, GError **error) { if (gpg_verify_summary) { if (summary == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "GPG verification enabled, but no summary found (check that the configured URL in remote config is correct)"); + "GPG verification enabled, but no summary found (check that the configured " + "URL in remote config is correct)"); return FALSE; } if (signatures == NULL) { g_set_error (error, OSTREE_GPG_ERROR, OSTREE_GPG_ERROR_NO_SIGNATURE, - "GPG verification enabled, but no summary signatures found (use gpg-verify-summary=false in remote config to disable)"); + "GPG verification enabled, but no summary signatures found (use " + "gpg-verify-summary=false in remote config to disable)"); return FALSE; } /* Verify any summary signatures. */ if (summary != NULL && signatures != NULL) { - g_autoptr(OstreeGpgVerifyResult) result = NULL; - - result = ostree_repo_verify_summary (self, - name, - summary, - signatures, - cancellable, - error); + g_autoptr (OstreeGpgVerifyResult) result = NULL; + + result = ostree_repo_verify_summary (self, name, summary, signatures, cancellable, error); if (!ostree_gpg_verify_result_require_valid_signature (result, error)) return FALSE; } @@ -2899,26 +2710,29 @@ _ostree_repo_verify_summary (OstreeRepo *self, if (summary == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Signature verification enabled, but no summary found (check that the configured URL in remote config is correct)"); + "Signature verification enabled, but no summary found (check that the " + "configured URL in remote config is correct)"); return FALSE; } if (signatures == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Signature verification enabled, but no summary signatures found (use sign-verify-summary=false in remote config to disable)"); + "Signature verification enabled, but no summary signatures found (use " + "sign-verify-summary=false in remote config to disable)"); return FALSE; } /* Verify any summary signatures. */ if (summary != NULL && signatures != NULL) { - g_autoptr(GVariant) sig_variant = NULL; + g_autoptr (GVariant) sig_variant = NULL; - sig_variant = g_variant_new_from_bytes (OSTREE_SUMMARY_SIG_GVARIANT_FORMAT, - signatures, FALSE); + sig_variant + = g_variant_new_from_bytes (OSTREE_SUMMARY_SIG_GVARIANT_FORMAT, signatures, FALSE); - if (!_sign_verify_for_remote (signapi_summary_verifiers, summary, sig_variant, NULL, error)) + if (!_sign_verify_for_remote (signapi_summary_verifiers, summary, sig_variant, NULL, + error)) return FALSE; } } @@ -2927,11 +2741,9 @@ _ostree_repo_verify_summary (OstreeRepo *self, } static void -_ostree_repo_load_cache_summary_properties (OstreeRepo *self, - const char *filename, - const char *extension, - char **out_etag, - guint64 *out_last_modified) +_ostree_repo_load_cache_summary_properties (OstreeRepo *self, const char *filename, + const char *extension, char **out_etag, + guint64 *out_last_modified) { const char *file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", filename, extension); glnx_autofd int fd = -1; @@ -2944,7 +2756,7 @@ _ostree_repo_load_cache_summary_properties (OstreeRepo *self, if (out_etag != NULL) { - g_autoptr(GBytes) etag_bytes = glnx_fgetxattr_bytes (fd, "user.etag", NULL); + g_autoptr (GBytes) etag_bytes = glnx_fgetxattr_bytes (fd, "user.etag", NULL); if (etag_bytes != NULL) { const guint8 *buf; @@ -2965,7 +2777,7 @@ _ostree_repo_load_cache_summary_properties (OstreeRepo *self, /* Nul-terminate and return */ if (buf_len > 0) - *out_etag = g_strndup ((const char *) buf, buf_len); + *out_etag = g_strndup ((const char *)buf, buf_len); else *out_etag = NULL; } @@ -2985,16 +2797,12 @@ _ostree_repo_load_cache_summary_properties (OstreeRepo *self, } static gboolean -_ostree_repo_load_cache_summary_file (OstreeRepo *self, - const char *filename, - const char *extension, - GBytes **out_data, - GCancellable *cancellable, - GError **error) +_ostree_repo_load_cache_summary_file (OstreeRepo *self, const char *filename, const char *extension, + GBytes **out_data, GCancellable *cancellable, GError **error) { const char *file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", filename, extension); glnx_autofd int fd = -1; - g_autoptr(GBytes) data = NULL; + g_autoptr (GBytes) data = NULL; *out_data = NULL; @@ -3013,44 +2821,39 @@ _ostree_repo_load_cache_summary_file (OstreeRepo *self, if (!data) return FALSE; - *out_data =g_steal_pointer (&data); + *out_data = g_steal_pointer (&data); return TRUE; } /* Load the summary from the cache if the provided .sig file is the same as the cached version. */ static gboolean -_ostree_repo_load_cache_summary_if_same_sig (OstreeRepo *self, - const char *remote, - GBytes *summary_sig, - GBytes **out_summary, - GCancellable *cancellable, - GError **error) +_ostree_repo_load_cache_summary_if_same_sig (OstreeRepo *self, const char *remote, + GBytes *summary_sig, GBytes **out_summary, + GCancellable *cancellable, GError **error) { - g_autoptr(GBytes) old_sig_contents = NULL; + g_autoptr (GBytes) old_sig_contents = NULL; *out_summary = NULL; - if (!_ostree_repo_load_cache_summary_file (self, remote, ".sig", - &old_sig_contents, - cancellable, error)) + if (!_ostree_repo_load_cache_summary_file (self, remote, ".sig", &old_sig_contents, cancellable, + error)) return FALSE; - if (old_sig_contents != NULL && - g_bytes_compare (old_sig_contents, summary_sig) == 0) + if (old_sig_contents != NULL && g_bytes_compare (old_sig_contents, summary_sig) == 0) { - g_autoptr(GBytes) summary_data = NULL; + g_autoptr (GBytes) summary_data = NULL; - if (!_ostree_repo_load_cache_summary_file (self, remote, NULL, - &summary_data, - cancellable, error)) + if (!_ostree_repo_load_cache_summary_file (self, remote, NULL, &summary_data, cancellable, + error)) return FALSE; if (summary_data == NULL) { /* Cached signature without cached summary, remove the signature */ - const char *summary_cache_sig_file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote, ".sig"); - (void) unlinkat (self->cache_dir_fd, summary_cache_sig_file, 0); + const char *summary_cache_sig_file + = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", remote, ".sig"); + (void)unlinkat (self->cache_dir_fd, summary_cache_sig_file, 0); } else *out_summary = g_steal_pointer (&summary_data); @@ -3060,17 +2863,14 @@ _ostree_repo_load_cache_summary_if_same_sig (OstreeRepo *self, } static void -store_file_cache_properties (int dir_fd, - const char *filename, - const char *etag, - guint64 last_modified) +store_file_cache_properties (int dir_fd, const char *filename, const char *etag, + guint64 last_modified) { glnx_autofd int fd = -1; - struct timespec time_vals[] = - { - { .tv_sec = last_modified, .tv_nsec = UTIME_OMIT }, /* access, leave unchanged */ - { .tv_sec = last_modified, .tv_nsec = 0 }, /* modification */ - }; + struct timespec time_vals[] = { + { .tv_sec = last_modified, .tv_nsec = UTIME_OMIT }, /* access, leave unchanged */ + { .tv_sec = last_modified, .tv_nsec = 0 }, /* modification */ + }; if (!glnx_openat_rdonly (dir_fd, filename, TRUE, &fd, NULL)) return; @@ -3085,14 +2885,9 @@ store_file_cache_properties (int dir_fd, } static gboolean -_ostree_repo_save_cache_summary_file (OstreeRepo *self, - const char *filename, - const char *extension, - GBytes *data, - const char *etag, - guint64 last_modified, - GCancellable *cancellable, - GError **error) +_ostree_repo_save_cache_summary_file (OstreeRepo *self, const char *filename, const char *extension, + GBytes *data, const char *etag, guint64 last_modified, + GCancellable *cancellable, GError **error) { const char *file = glnx_strjoina (_OSTREE_SUMMARY_CACHE_DIR, "/", filename, extension); glnx_autofd int fd = -1; @@ -3100,15 +2895,14 @@ _ostree_repo_save_cache_summary_file (OstreeRepo *self, if (self->cache_dir_fd == -1) return TRUE; - if (!glnx_shutil_mkdir_p_at (self->cache_dir_fd, _OSTREE_SUMMARY_CACHE_DIR, DEFAULT_DIRECTORY_MODE, cancellable, error)) + if (!glnx_shutil_mkdir_p_at (self->cache_dir_fd, _OSTREE_SUMMARY_CACHE_DIR, + DEFAULT_DIRECTORY_MODE, cancellable, error)) return FALSE; - if (!glnx_file_replace_contents_at (self->cache_dir_fd, - file, - g_bytes_get_data (data, NULL), - g_bytes_get_size (data), - self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : GLNX_FILE_REPLACE_DATASYNC_NEW, - cancellable, error)) + if (!glnx_file_replace_contents_at ( + self->cache_dir_fd, file, g_bytes_get_data (data, NULL), g_bytes_get_size (data), + self->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : GLNX_FILE_REPLACE_DATASYNC_NEW, + cancellable, error)) return FALSE; /* Store the caching properties. This is non-fatal on failure. */ @@ -3119,40 +2913,27 @@ _ostree_repo_save_cache_summary_file (OstreeRepo *self, /* Replace the current summary+signature with new versions */ static gboolean -_ostree_repo_cache_summary (OstreeRepo *self, - const char *remote, - GBytes *summary, - const char *summary_etag, - guint64 summary_last_modified, - GBytes *summary_sig, - const char *summary_sig_etag, - guint64 summary_sig_last_modified, - GCancellable *cancellable, - GError **error) +_ostree_repo_cache_summary (OstreeRepo *self, const char *remote, GBytes *summary, + const char *summary_etag, guint64 summary_last_modified, + GBytes *summary_sig, const char *summary_sig_etag, + guint64 summary_sig_last_modified, GCancellable *cancellable, + GError **error) { - if (!_ostree_repo_save_cache_summary_file (self, remote, NULL, - summary, - summary_etag, summary_last_modified, - cancellable, error)) + if (!_ostree_repo_save_cache_summary_file (self, remote, NULL, summary, summary_etag, + summary_last_modified, cancellable, error)) return FALSE; - if (!_ostree_repo_save_cache_summary_file (self, remote, ".sig", - summary_sig, - summary_sig_etag, summary_sig_last_modified, - cancellable, error)) + if (!_ostree_repo_save_cache_summary_file (self, remote, ".sig", summary_sig, summary_sig_etag, + summary_sig_last_modified, cancellable, error)) return FALSE; return TRUE; } static OstreeFetcher * -_ostree_repo_remote_new_fetcher (OstreeRepo *self, - const char *remote_name, - gboolean gzip, - GVariant *extra_headers, - const char *append_user_agent, - OstreeFetcherSecurityState *out_state, - GError **error) +_ostree_repo_remote_new_fetcher (OstreeRepo *self, const char *remote_name, gboolean gzip, + GVariant *extra_headers, const char *append_user_agent, + OstreeFetcherSecurityState *out_state, GError **error) { OstreeFetcher *fetcher = NULL; OstreeFetcherConfigFlags fetcher_flags = 0; @@ -3163,8 +2944,7 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self, g_return_val_if_fail (OSTREE_IS_REPO (self), NULL); g_return_val_if_fail (remote_name != NULL, NULL); - if (!ostree_repo_get_remote_boolean_option (self, remote_name, - "tls-permissive", FALSE, + if (!ostree_repo_get_remote_boolean_option (self, remote_name, "tls-permissive", FALSE, &tls_permissive, error)) goto out; @@ -3177,15 +2957,15 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self, if (gzip) fetcher_flags |= OSTREE_FETCHER_FLAGS_TRANSFER_GZIP; - { gboolean http2_default = TRUE; + { + gboolean http2_default = TRUE; #ifndef BUILDOPT_HTTP2 http2_default = FALSE; #endif gboolean http2; - if (!ostree_repo_get_remote_boolean_option (self, remote_name, - "http2", http2_default, - &http2, error)) + if (!ostree_repo_get_remote_boolean_option (self, remote_name, "http2", http2_default, &http2, + error)) goto out; if (!http2) fetcher_flags |= OSTREE_FETCHER_FLAGS_DISABLE_HTTP2; @@ -3197,12 +2977,10 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self, g_autofree char *tls_client_cert_path = NULL; g_autofree char *tls_client_key_path = NULL; - if (!ostree_repo_get_remote_option (self, remote_name, - "tls-client-cert-path", NULL, + if (!ostree_repo_get_remote_option (self, remote_name, "tls-client-cert-path", NULL, &tls_client_cert_path, error)) goto out; - if (!ostree_repo_get_remote_option (self, remote_name, - "tls-client-key-path", NULL, + if (!ostree_repo_get_remote_option (self, remote_name, "tls-client-key-path", NULL, &tls_client_key_path, error)) goto out; @@ -3223,9 +3001,8 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self, { g_autofree char *tls_ca_path = NULL; - if (!ostree_repo_get_remote_option (self, remote_name, - "tls-ca-path", NULL, - &tls_ca_path, error)) + if (!ostree_repo_get_remote_option (self, remote_name, "tls-ca-path", NULL, &tls_ca_path, + error)) goto out; if (tls_ca_path != NULL) @@ -3241,9 +3018,7 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self, { g_autofree char *http_proxy = NULL; - if (!ostree_repo_get_remote_option (self, remote_name, - "proxy", NULL, - &http_proxy, error)) + if (!ostree_repo_get_remote_option (self, remote_name, "proxy", NULL, &http_proxy, error)) goto out; if (http_proxy != NULL && http_proxy[0] != '\0') @@ -3256,9 +3031,9 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self, /* TODO; port away from this; a bit hard since both libsoup and libcurl * expect a file. Doing ot_fdrel_to_gfile() works for now though. */ - GFile*repo_path = ostree_repo_get_path (self); - g_autofree char *jar_path = - g_build_filename (gs_file_get_path_cached (repo_path), cookie_file, NULL); + GFile *repo_path = ostree_repo_get_path (self); + g_autofree char *jar_path + = g_build_filename (gs_file_get_path_cached (repo_path), cookie_file, NULL); if (g_file_test (jar_path, G_FILE_TEST_IS_REGULAR)) _ostree_fetcher_set_cookie_jar (fetcher, jar_path); @@ -3282,20 +3057,13 @@ out: } static gboolean -_ostree_preload_metadata_file (OstreeRepo *self, - OstreeFetcher *fetcher, - GPtrArray *mirrorlist, - const char *filename, - gboolean is_metalink, - const char *if_none_match, - guint64 if_modified_since, - guint n_network_retries, - GBytes **out_bytes, - gboolean *out_not_modified, - char **out_etag, - guint64 *out_last_modified, - GCancellable *cancellable, - GError **error) +_ostree_preload_metadata_file (OstreeRepo *self, OstreeFetcher *fetcher, GPtrArray *mirrorlist, + const char *filename, gboolean is_metalink, + const char *if_none_match, guint64 if_modified_since, + guint n_network_retries, GBytes **out_bytes, + gboolean *out_not_modified, char **out_etag, + guint64 *out_last_modified, GCancellable *cancellable, + GError **error) { if (is_metalink) { @@ -3303,13 +3071,10 @@ _ostree_preload_metadata_file (OstreeRepo *self, /* the metalink uri is buried in the mirrorlist as the first (and only) * element */ - g_autoptr(OstreeMetalink) metalink = - _ostree_metalink_new (fetcher, filename, - OSTREE_MAX_METADATA_SIZE, - mirrorlist->pdata[0], n_network_retries); + g_autoptr (OstreeMetalink) metalink = _ostree_metalink_new ( + fetcher, filename, OSTREE_MAX_METADATA_SIZE, mirrorlist->pdata[0], n_network_retries); - _ostree_metalink_request_sync (metalink, NULL, out_bytes, - cancellable, &local_error); + _ostree_metalink_request_sync (metalink, NULL, out_bytes, cancellable, &local_error); if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) { @@ -3326,46 +3091,38 @@ _ostree_preload_metadata_file (OstreeRepo *self, } else { - return _ostree_fetcher_mirrored_request_to_membuf (fetcher, mirrorlist, filename, - OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - if_none_match, if_modified_since, - n_network_retries, - out_bytes, out_not_modified, out_etag, out_last_modified, - OSTREE_MAX_METADATA_SIZE, - cancellable, error); + return _ostree_fetcher_mirrored_request_to_membuf ( + fetcher, mirrorlist, filename, OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, if_none_match, + if_modified_since, n_network_retries, out_bytes, out_not_modified, out_etag, + out_last_modified, OSTREE_MAX_METADATA_SIZE, cancellable, error); } } static gboolean -fetch_mirrorlist (OstreeFetcher *fetcher, - const char *mirrorlist_url, - guint n_network_retries, - GPtrArray **out_mirrorlist, - GCancellable *cancellable, - GError **error) +fetch_mirrorlist (OstreeFetcher *fetcher, const char *mirrorlist_url, guint n_network_retries, + GPtrArray **out_mirrorlist, GCancellable *cancellable, GError **error) { - g_autoptr(GPtrArray) ret_mirrorlist = - g_ptr_array_new_with_free_func ((GDestroyNotify) _ostree_fetcher_uri_free); + g_autoptr (GPtrArray) ret_mirrorlist + = g_ptr_array_new_with_free_func ((GDestroyNotify)_ostree_fetcher_uri_free); - g_autoptr(OstreeFetcherURI) mirrorlist = _ostree_fetcher_uri_parse (mirrorlist_url, error); + g_autoptr (OstreeFetcherURI) mirrorlist = _ostree_fetcher_uri_parse (mirrorlist_url, error); if (!mirrorlist) return FALSE; g_autofree char *contents = NULL; - if (!fetch_uri_contents_utf8_sync (fetcher, mirrorlist, n_network_retries, - &contents, cancellable, error)) - return glnx_prefix_error (error, "While fetching mirrorlist '%s'", - mirrorlist_url); + if (!fetch_uri_contents_utf8_sync (fetcher, mirrorlist, n_network_retries, &contents, cancellable, + error)) + return glnx_prefix_error (error, "While fetching mirrorlist '%s'", mirrorlist_url); /* go through each mirror in mirrorlist and do a quick sanity check that it * works so that we don't waste the fetcher's time when it goes through them * */ - g_auto(GStrv) lines = g_strsplit (contents, "\n", -1); + g_auto (GStrv) lines = g_strsplit (contents, "\n", -1); g_debug ("Scanning mirrorlist from '%s'", mirrorlist_url); for (char **iter = lines; iter && *iter; iter++) { const char *mirror_uri_str = *iter; - g_autoptr(OstreeFetcherURI) mirror_uri = NULL; + g_autoptr (OstreeFetcherURI) mirror_uri = NULL; g_autofree char *scheme = NULL; /* let's be nice and support empty lines and comments */ @@ -3397,15 +3154,16 @@ fetch_mirrorlist (OstreeFetcher *fetcher, if (ret_mirrorlist->len == 0) { GError *local_error = NULL; - g_autoptr(OstreeFetcherURI) config_uri = _ostree_fetcher_uri_new_subpath (mirror_uri, "config"); + g_autoptr (OstreeFetcherURI) config_uri + = _ostree_fetcher_uri_new_subpath (mirror_uri, "config"); - if (fetch_uri_contents_utf8_sync (fetcher, config_uri, n_network_retries, - NULL, cancellable, &local_error)) + if (fetch_uri_contents_utf8_sync (fetcher, config_uri, n_network_retries, NULL, + cancellable, &local_error)) g_ptr_array_add (ret_mirrorlist, g_steal_pointer (&mirror_uri)); else { - g_debug ("Failed to fetch config from mirror '%s': %s", - mirror_uri_str, local_error->message); + g_debug ("Failed to fetch config from mirror '%s': %s", mirror_uri_str, + local_error->message); g_clear_error (&local_error); } } @@ -3416,22 +3174,17 @@ fetch_mirrorlist (OstreeFetcher *fetcher, } if (ret_mirrorlist->len == 0) - return glnx_throw (error, "No valid mirrors were found in mirrorlist '%s'", - mirrorlist_url); + return glnx_throw (error, "No valid mirrors were found in mirrorlist '%s'", mirrorlist_url); *out_mirrorlist = g_steal_pointer (&ret_mirrorlist); return TRUE; } static gboolean -compute_effective_mirrorlist (OstreeRepo *self, - const char *remote_name_or_baseurl, - const char *url_override, - OstreeFetcher *fetcher, - guint n_network_retries, - GPtrArray **out_mirrorlist, - GCancellable *cancellable, - GError **error) +compute_effective_mirrorlist (OstreeRepo *self, const char *remote_name_or_baseurl, + const char *url_override, OstreeFetcher *fetcher, + guint n_network_retries, GPtrArray **out_mirrorlist, + GCancellable *cancellable, GError **error) { g_autofree char *baseurl = NULL; @@ -3442,16 +3195,13 @@ compute_effective_mirrorlist (OstreeRepo *self, if (g_str_has_prefix (baseurl, "mirrorlist=")) { - if (!fetch_mirrorlist (fetcher, - baseurl + strlen ("mirrorlist="), - n_network_retries, - out_mirrorlist, - cancellable, error)) + if (!fetch_mirrorlist (fetcher, baseurl + strlen ("mirrorlist="), n_network_retries, + out_mirrorlist, cancellable, error)) return FALSE; } else { - g_autoptr(OstreeFetcherURI) baseuri = _ostree_fetcher_uri_parse (baseurl, error); + g_autoptr (OstreeFetcherURI) baseuri = _ostree_fetcher_uri_parse (baseurl, error); if (!baseuri) return FALSE; @@ -3459,8 +3209,7 @@ compute_effective_mirrorlist (OstreeRepo *self, if (!_ostree_fetcher_uri_validate (baseuri, error)) return FALSE; - *out_mirrorlist = - g_ptr_array_new_with_free_func ((GDestroyNotify) _ostree_fetcher_uri_free); + *out_mirrorlist = g_ptr_array_new_with_free_func ((GDestroyNotify)_ostree_fetcher_uri_free); g_ptr_array_add (*out_mirrorlist, g_steal_pointer (&baseuri)); } return TRUE; @@ -3470,15 +3219,12 @@ compute_effective_mirrorlist (OstreeRepo *self, * any options specific to this pull (such as extra headers). */ static gboolean -reinitialize_fetcher (OtPullData *pull_data, const char *remote_name, - GError **error) +reinitialize_fetcher (OtPullData *pull_data, const char *remote_name, GError **error) { g_clear_object (&pull_data->fetcher); - pull_data->fetcher = _ostree_repo_remote_new_fetcher (pull_data->repo, remote_name, FALSE, - pull_data->extra_headers, - pull_data->append_user_agent, - &pull_data->fetcher_security_state, - error); + pull_data->fetcher = _ostree_repo_remote_new_fetcher ( + pull_data->repo, remote_name, FALSE, pull_data->extra_headers, pull_data->append_user_agent, + &pull_data->fetcher_security_state, error); if (pull_data->fetcher == NULL) return FALSE; @@ -3486,17 +3232,14 @@ reinitialize_fetcher (OtPullData *pull_data, const char *remote_name, } static gboolean -initiate_delta_request (OtPullData *pull_data, - const OstreeCollectionRef *ref, - const char *to_revision, - const char *delta_from_revision, - GError **error) +initiate_delta_request (OtPullData *pull_data, const OstreeCollectionRef *ref, + const char *to_revision, const char *delta_from_revision, GError **error) { DeltaSearchResult deltares; /* Look for a delta to @to_revision in the summary data */ - if (!get_best_static_delta_start_for (pull_data, to_revision, &deltares, - pull_data->cancellable, error)) + if (!get_best_static_delta_start_for (pull_data, to_revision, &deltares, pull_data->cancellable, + error)) return FALSE; switch (deltares.result) @@ -3509,11 +3252,13 @@ initiate_delta_request (OtPullData *pull_data, return FALSE; } else /* No deltas, fall back to object fetches. */ - queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, ref); + queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, + 0, ref); } break; case DELTA_SEARCH_RESULT_FROM: - enqueue_one_static_delta_superblock_request (pull_data, deltares.from_revision, to_revision, ref); + enqueue_one_static_delta_superblock_request (pull_data, deltares.from_revision, to_revision, + ref); break; case DELTA_SEARCH_RESULT_SCRATCH: { @@ -3522,7 +3267,8 @@ initiate_delta_request (OtPullData *pull_data, * commits out of date; so doing an object pull is likely more * bandwidth efficient. */ if (delta_from_revision != NULL) - queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, ref); + queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, + 0, ref); else enqueue_one_static_delta_superblock_request (pull_data, NULL, to_revision, ref); } @@ -3537,7 +3283,8 @@ initiate_delta_request (OtPullData *pull_data, if (pull_data->require_static_deltas) break; else - queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, ref); + queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, + 0, ref); } } @@ -3556,17 +3303,16 @@ initiate_delta_request (OtPullData *pull_data, * `disable_static_deltas` and `require_static_deltas`. */ static gboolean -initiate_request (OtPullData *pull_data, - const OstreeCollectionRef *ref, - const char *to_revision, - GError **error) +initiate_request (OtPullData *pull_data, const OstreeCollectionRef *ref, const char *to_revision, + GError **error) { g_autofree char *delta_from_revision = NULL; /* Are deltas disabled? OK, just start an object fetch and be done */ if (pull_data->disable_static_deltas) { - queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, ref); + queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, + ref); return TRUE; } @@ -3577,8 +3323,7 @@ initiate_request (OtPullData *pull_data, g_autofree char *refspec = NULL; if (pull_data->remote_name != NULL) refspec = g_strdup_printf ("%s:%s", pull_data->remote_name, ref->ref_name); - if (!ostree_repo_resolve_rev (pull_data->repo, - refspec ?: ref->ref_name, TRUE, + if (!ostree_repo_resolve_rev (pull_data->repo, refspec ?: ref->ref_name, TRUE, &delta_from_revision, error)) return FALSE; } @@ -3622,9 +3367,11 @@ initiate_request (OtPullData *pull_data, * delta. */ if (delta_from_revision && g_str_equal (delta_from_revision, to_revision)) - queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, ref); + queue_scan_one_metadata_object (pull_data, to_revision, OSTREE_OBJECT_TYPE_COMMIT, NULL, 0, + ref); else - enqueue_one_static_delta_superblock_request (pull_data, delta_from_revision ?: NULL, to_revision, ref); + enqueue_one_static_delta_superblock_request (pull_data, delta_from_revision ?: NULL, + to_revision, ref); } else { @@ -3638,10 +3385,11 @@ initiate_request (OtPullData *pull_data, } static gboolean -all_requested_refs_have_commit (GHashTable *requested_refs /* (element-type OstreeCollectionRef utf8) */) +all_requested_refs_have_commit ( + GHashTable *requested_refs /* (element-type OstreeCollectionRef utf8) */) { - GLNX_HASH_TABLE_FOREACH_KV (requested_refs, const OstreeCollectionRef*, ref, - const char*, override_commitid) + GLNX_HASH_TABLE_FOREACH_KV (requested_refs, const OstreeCollectionRef *, ref, const char *, + override_commitid) { /* Note: "" override means whatever is latest */ if (override_commitid == NULL || *override_commitid == 0) @@ -3686,15 +3434,21 @@ all_requested_refs_have_commit (GHashTable *requested_refs /* (element-type Ostr * * `disable-static-deltas` (`b`): Do not use static deltas * * `require-static-deltas` (`b`): Require static deltas * * `override-commit-ids` (`as`): Array of specific commit IDs to fetch for refs - * * `timestamp-check` (`b`): Verify commit timestamps are newer than current (when pulling via ref); Since: 2017.11 - * * `timestamp-check-from-rev` (`s`): Verify that all fetched commit timestamps are newer than timestamp of given rev; Since: 2020.4 - * * `max-metadata-size` (`t`): Restrict metadata objects to a maximum number of bytes; 0 to disable. Since: 2018.9 + * * `timestamp-check` (`b`): Verify commit timestamps are newer than current (when pulling via + * ref); Since: 2017.11 + * * `timestamp-check-from-rev` (`s`): Verify that all fetched commit timestamps are newer than + * timestamp of given rev; Since: 2020.4 + * * `max-metadata-size` (`t`): Restrict metadata objects to a maximum number of bytes; 0 to + * disable. Since: 2018.9 * * `dry-run` (`b`): Only print information on what will be downloaded (requires static deltas) * * `override-url` (`s`): Fetch objects from this URL if remote specifies no metalink in options - * * `inherit-transaction` (`b`): Don't initiate, finish or abort a transaction, useful to do multiple pulls in one transaction. + * * `inherit-transaction` (`b`): Don't initiate, finish or abort a transaction, useful to do + * multiple pulls in one transaction. * * `http-headers` (`a(ss)`): Additional headers to add to all HTTP requests - * * `update-frequency` (`u`): Frequency to call the async progress callback in milliseconds, if any; only values higher than 0 are valid - * * `localcache-repos` (`as`): File paths for local repos to use as caches when doing remote fetches + * * `update-frequency` (`u`): Frequency to call the async progress callback in milliseconds, if + * any; only values higher than 0 are valid + * * `localcache-repos` (`as`): File paths for local repos to use as caches when doing remote + * fetches * * `append-user-agent` (`s`): Additional string to append to the user agent * * `n-network-retries` (`u`): Number of times to retry each download on receiving * a transient network error, such as a socket timeout; default is 5, 0 @@ -3719,24 +3473,24 @@ all_requested_refs_have_commit (GHashTable *requested_refs /* (element-type Ostr * Since: 2020.9 */ gboolean -ostree_repo_pull_with_options (OstreeRepo *self, - const char *remote_name_or_baseurl, - GVariant *options, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GError **error) +ostree_repo_pull_with_options (OstreeRepo *self, const char *remote_name_or_baseurl, + GVariant *options, OstreeAsyncProgress *progress, + GCancellable *cancellable, GError **error) { gboolean ret = FALSE; - g_autoptr(GBytes) bytes_summary = NULL; + g_autoptr (GBytes) bytes_summary = NULL; gboolean summary_not_modified = FALSE; g_autofree char *summary_etag = NULL; guint64 summary_last_modified = 0; g_autofree char *metalink_url_str = NULL; - g_autoptr(GHashTable) requested_refs_to_fetch = NULL; /* (element-type OstreeCollectionRef utf8) */ - g_autoptr(GHashTable) commits_to_fetch = NULL; + g_autoptr (GHashTable) requested_refs_to_fetch + = NULL; /* (element-type OstreeCollectionRef utf8) */ + g_autoptr (GHashTable) commits_to_fetch = NULL; g_autofree char *remote_mode_str = NULL; - g_autoptr(OstreeMetalink) metalink = NULL; - OtPullData pull_data_real = { 0, }; + g_autoptr (OstreeMetalink) metalink = NULL; + OtPullData pull_data_real = { + 0, + }; OtPullData *pull_data = &pull_data_real; GKeyFile *remote_config = NULL; char **configured_branches = NULL; @@ -3747,9 +3501,9 @@ ostree_repo_pull_with_options (OstreeRepo *self, const char *dir_to_pull = NULL; g_autofree char **dirs_to_pull = NULL; g_autofree char **refs_to_fetch = NULL; - g_autoptr(GVariantIter) collection_refs_iter = NULL; + g_autoptr (GVariantIter) collection_refs_iter = NULL; g_autofree char **override_commit_ids = NULL; - g_autoptr(GSource) update_timeout = NULL; + g_autoptr (GSource) update_timeout = NULL; gboolean opt_per_object_fsync = FALSE; gboolean opt_gpg_verify_set = FALSE; gboolean opt_gpg_verify_summary_set = FALSE; @@ -3763,17 +3517,20 @@ ostree_repo_pull_with_options (OstreeRepo *self, const char *url_override = NULL; gboolean inherit_transaction = FALSE; gboolean require_summary_for_mirror = FALSE; - g_autoptr(GHashTable) updated_requested_refs_to_fetch = NULL; /* (element-type OstreeCollectionRef utf8) */ + g_autoptr (GHashTable) updated_requested_refs_to_fetch + = NULL; /* (element-type OstreeCollectionRef utf8) */ gsize i; g_autofree char **opt_localcache_repos = NULL; - g_autoptr(GVariantIter) ref_keyring_map_iter = NULL; - g_autoptr(GVariant) summary_bytes_v = NULL; - g_autoptr(GVariant) summary_sig_bytes_v = NULL; + g_autoptr (GVariantIter) ref_keyring_map_iter = NULL; + g_autoptr (GVariant) summary_bytes_v = NULL; + g_autoptr (GVariant) summary_sig_bytes_v = NULL; /* If refs or collection-refs has exactly one value, this will point to that * value, otherwise NULL. Used for logging. */ const char *the_ref_to_fetch = NULL; - OstreeRepoTransactionStats tstats = { 0, }; + OstreeRepoTransactionStats tstats = { + 0, + }; gboolean remote_mode_loaded = FALSE; /* Default */ @@ -3782,43 +3539,47 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (options) { int flags_i = OSTREE_REPO_PULL_FLAGS_NONE; - (void) g_variant_lookup (options, "refs", "^a&s", &refs_to_fetch); - opt_collection_refs_set = - g_variant_lookup (options, "collection-refs", "a(sss)", &collection_refs_iter); - (void) g_variant_lookup (options, "flags", "i", &flags_i); + (void)g_variant_lookup (options, "refs", "^a&s", &refs_to_fetch); + opt_collection_refs_set + = g_variant_lookup (options, "collection-refs", "a(sss)", &collection_refs_iter); + (void)g_variant_lookup (options, "flags", "i", &flags_i); /* Reduce risk of issues if enum happens to be 64 bit for some reason */ flags = flags_i; - (void) g_variant_lookup (options, "subdir", "&s", &dir_to_pull); - (void) g_variant_lookup (options, "subdirs", "^a&s", &dirs_to_pull); - (void) g_variant_lookup (options, "override-remote-name", "s", &pull_data->remote_refspec_name); - opt_gpg_verify_set = - g_variant_lookup (options, "gpg-verify", "b", &pull_data->gpg_verify); - opt_gpg_verify_summary_set = - g_variant_lookup (options, "gpg-verify-summary", "b", &pull_data->gpg_verify_summary); + (void)g_variant_lookup (options, "subdir", "&s", &dir_to_pull); + (void)g_variant_lookup (options, "subdirs", "^a&s", &dirs_to_pull); + (void)g_variant_lookup (options, "override-remote-name", "s", + &pull_data->remote_refspec_name); + opt_gpg_verify_set = g_variant_lookup (options, "gpg-verify", "b", &pull_data->gpg_verify); + opt_gpg_verify_summary_set + = g_variant_lookup (options, "gpg-verify-summary", "b", &pull_data->gpg_verify_summary); g_variant_lookup (options, "disable-sign-verify", "b", &disable_sign_verify); g_variant_lookup (options, "disable-sign-verify-summary", "b", &disable_sign_verify_summary); - (void) g_variant_lookup (options, "depth", "i", &pull_data->maxdepth); - (void) g_variant_lookup (options, "disable-static-deltas", "b", &pull_data->disable_static_deltas); - (void) g_variant_lookup (options, "require-static-deltas", "b", &pull_data->require_static_deltas); - (void) g_variant_lookup (options, "override-commit-ids", "^a&s", &override_commit_ids); - (void) g_variant_lookup (options, "dry-run", "b", &pull_data->dry_run); - (void) g_variant_lookup (options, "per-object-fsync", "b", &opt_per_object_fsync); - (void) g_variant_lookup (options, "override-url", "&s", &url_override); - (void) g_variant_lookup (options, "inherit-transaction", "b", &inherit_transaction); - (void) g_variant_lookup (options, "http-headers", "@a(ss)", &pull_data->extra_headers); - (void) g_variant_lookup (options, "update-frequency", "u", &update_frequency); - (void) g_variant_lookup (options, "localcache-repos", "^a&s", &opt_localcache_repos); - (void) g_variant_lookup (options, "timestamp-check", "b", &pull_data->timestamp_check); - (void) g_variant_lookup (options, "timestamp-check-from-rev", "s", &pull_data->timestamp_check_from_rev); - (void) g_variant_lookup (options, "max-metadata-size", "t", &pull_data->max_metadata_size); - (void) g_variant_lookup (options, "append-user-agent", "s", &pull_data->append_user_agent); - opt_n_network_retries_set = - g_variant_lookup (options, "n-network-retries", "u", &pull_data->n_network_retries); - opt_ref_keyring_map_set = - g_variant_lookup (options, "ref-keyring-map", "a(sss)", &ref_keyring_map_iter); - (void) g_variant_lookup (options, "summary-bytes", "@ay", &summary_bytes_v); - (void) g_variant_lookup (options, "summary-sig-bytes", "@ay", &summary_sig_bytes_v); - (void) g_variant_lookup (options, "disable-verify-bindings", "b", &pull_data->disable_verify_bindings); + (void)g_variant_lookup (options, "depth", "i", &pull_data->maxdepth); + (void)g_variant_lookup (options, "disable-static-deltas", "b", + &pull_data->disable_static_deltas); + (void)g_variant_lookup (options, "require-static-deltas", "b", + &pull_data->require_static_deltas); + (void)g_variant_lookup (options, "override-commit-ids", "^a&s", &override_commit_ids); + (void)g_variant_lookup (options, "dry-run", "b", &pull_data->dry_run); + (void)g_variant_lookup (options, "per-object-fsync", "b", &opt_per_object_fsync); + (void)g_variant_lookup (options, "override-url", "&s", &url_override); + (void)g_variant_lookup (options, "inherit-transaction", "b", &inherit_transaction); + (void)g_variant_lookup (options, "http-headers", "@a(ss)", &pull_data->extra_headers); + (void)g_variant_lookup (options, "update-frequency", "u", &update_frequency); + (void)g_variant_lookup (options, "localcache-repos", "^a&s", &opt_localcache_repos); + (void)g_variant_lookup (options, "timestamp-check", "b", &pull_data->timestamp_check); + (void)g_variant_lookup (options, "timestamp-check-from-rev", "s", + &pull_data->timestamp_check_from_rev); + (void)g_variant_lookup (options, "max-metadata-size", "t", &pull_data->max_metadata_size); + (void)g_variant_lookup (options, "append-user-agent", "s", &pull_data->append_user_agent); + opt_n_network_retries_set + = g_variant_lookup (options, "n-network-retries", "u", &pull_data->n_network_retries); + opt_ref_keyring_map_set + = g_variant_lookup (options, "ref-keyring-map", "a(sss)", &ref_keyring_map_iter); + (void)g_variant_lookup (options, "summary-bytes", "@ay", &summary_bytes_v); + (void)g_variant_lookup (options, "summary-sig-bytes", "@ay", &summary_sig_bytes_v); + (void)g_variant_lookup (options, "disable-verify-bindings", "b", + &pull_data->disable_verify_bindings); if (pull_data->remote_refspec_name != NULL) pull_data->remote_name = g_strdup (pull_data->remote_refspec_name); @@ -3827,21 +3588,21 @@ ostree_repo_pull_with_options (OstreeRepo *self, #ifdef OSTREE_DISABLE_GPGME /* Explicitly fail here if gpg verification is requested and we have no GPG support */ if (pull_data->gpg_verify || pull_data->gpg_verify_summary) - { + { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "'%s': GPG feature is disabled at build time", - __FUNCTION__); + "'%s': GPG feature is disabled at build time", __FUNCTION__); goto out; - } + } #endif g_return_val_if_fail (OSTREE_IS_REPO (self), FALSE); g_return_val_if_fail (pull_data->maxdepth >= -1, FALSE); g_return_val_if_fail (!pull_data->timestamp_check || pull_data->maxdepth == 0, FALSE); - g_return_val_if_fail (!opt_collection_refs_set || - (refs_to_fetch == NULL && override_commit_ids == NULL), FALSE); + g_return_val_if_fail ( + !opt_collection_refs_set || (refs_to_fetch == NULL && override_commit_ids == NULL), FALSE); if (refs_to_fetch && override_commit_ids) - g_return_val_if_fail (g_strv_length (refs_to_fetch) == g_strv_length (override_commit_ids), FALSE); + g_return_val_if_fail (g_strv_length (refs_to_fetch) == g_strv_length (override_commit_ids), + FALSE); if (dir_to_pull) g_return_val_if_fail (dir_to_pull[0] == '/', FALSE); @@ -3849,7 +3610,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, for (i = 0; dirs_to_pull != NULL && dirs_to_pull[i] != NULL; i++) g_return_val_if_fail (dirs_to_pull[i][0] == '/', FALSE); - g_return_val_if_fail (!(pull_data->disable_static_deltas && pull_data->require_static_deltas), FALSE); + g_return_val_if_fail (!(pull_data->disable_static_deltas && pull_data->require_static_deltas), + FALSE); /* We only do dry runs with static deltas, because we don't really have any * in-advance information for bare fetches. @@ -3888,43 +3650,43 @@ ostree_repo_pull_with_options (OstreeRepo *self, pull_data->repo = self; pull_data->progress = progress; - pull_data->expected_commit_sizes = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, - (GDestroyNotify)g_free); - pull_data->commit_to_depth = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, - NULL); - pull_data->summary_deltas_checksums = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, - (GDestroyNotify)g_free); - pull_data->ref_original_commits = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, - (GDestroyNotify)NULL, - (GDestroyNotify)g_free); - pull_data->verified_commits = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, NULL); - pull_data->signapi_verified_commits = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, NULL); - pull_data->ref_keyring_map = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, - (GDestroyNotify)ostree_collection_ref_free, (GDestroyNotify)g_free); + pull_data->expected_commit_sizes = g_hash_table_new_full ( + g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free); + pull_data->commit_to_depth + = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL); + pull_data->summary_deltas_checksums = g_hash_table_new_full ( + g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)g_free); + pull_data->ref_original_commits + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, + (GDestroyNotify)NULL, (GDestroyNotify)g_free); + pull_data->verified_commits + = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL); + pull_data->signapi_verified_commits + = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL); + pull_data->ref_keyring_map + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, + (GDestroyNotify)ostree_collection_ref_free, (GDestroyNotify)g_free); pull_data->scanned_metadata = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, (GDestroyNotify)g_variant_unref, NULL); - pull_data->fetched_detached_metadata = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, (GDestroyNotify)variant_or_null_unref); - pull_data->requested_content = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, NULL); - pull_data->requested_fallback_content = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, NULL); + pull_data->fetched_detached_metadata = g_hash_table_new_full ( + g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)variant_or_null_unref); + pull_data->requested_content + = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL); + pull_data->requested_fallback_content + = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify)g_free, NULL); pull_data->requested_metadata = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, (GDestroyNotify)g_variant_unref, NULL); - pull_data->pending_fetch_content = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify)g_free, - (GDestroyNotify)fetch_object_data_free); - pull_data->pending_fetch_metadata = g_hash_table_new_full (ostree_hash_object_name, g_variant_equal, - (GDestroyNotify)g_variant_unref, - (GDestroyNotify)fetch_object_data_free); - pull_data->pending_fetch_delta_indexes = g_hash_table_new_full (NULL, NULL, (GDestroyNotify) fetch_delta_index_data_free, NULL); - pull_data->pending_fetch_delta_superblocks = g_hash_table_new_full (NULL, NULL, (GDestroyNotify) fetch_delta_super_data_free, NULL); - pull_data->pending_fetch_deltaparts = g_hash_table_new_full (NULL, NULL, (GDestroyNotify)fetch_static_delta_data_free, NULL); + pull_data->pending_fetch_content = g_hash_table_new_full ( + g_str_hash, g_str_equal, (GDestroyNotify)g_free, (GDestroyNotify)fetch_object_data_free); + pull_data->pending_fetch_metadata = g_hash_table_new_full ( + ostree_hash_object_name, g_variant_equal, (GDestroyNotify)g_variant_unref, + (GDestroyNotify)fetch_object_data_free); + pull_data->pending_fetch_delta_indexes + = g_hash_table_new_full (NULL, NULL, (GDestroyNotify)fetch_delta_index_data_free, NULL); + pull_data->pending_fetch_delta_superblocks + = g_hash_table_new_full (NULL, NULL, (GDestroyNotify)fetch_delta_super_data_free, NULL); + pull_data->pending_fetch_deltaparts + = g_hash_table_new_full (NULL, NULL, (GDestroyNotify)fetch_static_delta_data_free, NULL); if (opt_localcache_repos && *opt_localcache_repos) { @@ -3932,8 +3694,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, for (char **it = opt_localcache_repos; it && *it; it++) { const char *localcache_path = *it; - g_autoptr(GFile) localcache_file = g_file_new_for_path (localcache_path); - g_autoptr(OstreeRepo) cacherepo = ostree_repo_new (localcache_file); + g_autoptr (GFile) localcache_file = g_file_new_for_path (localcache_path); + g_autoptr (OstreeRepo) cacherepo = ostree_repo_new (localcache_file); if (!ostree_repo_open (cacherepo, cancellable, error)) goto out; g_ptr_array_add (pull_data->localcache_repos, g_steal_pointer (&cacherepo)); @@ -3962,10 +3724,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, /* For compatibility with pull-local, don't gpg verify local * pulls by default. */ - if ((pull_data->gpg_verify || - pull_data->gpg_verify_summary - ) && - pull_data->remote_name == NULL) + if ((pull_data->gpg_verify || pull_data->gpg_verify_summary) + && pull_data->remote_name == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Must specify remote name to enable gpg verification"); @@ -3995,23 +3755,19 @@ ostree_repo_pull_with_options (OstreeRepo *self, /* NOTE: If changing this, see the matching implementation in * ostree-sysroot-upgrader.c */ - if (!ostree_repo_get_remote_option (self, pull_data->remote_name, - "unconfigured-state", NULL, - &unconfigured_state, - error)) + if (!ostree_repo_get_remote_option (self, pull_data->remote_name, "unconfigured-state", NULL, + &unconfigured_state, error)) goto out; if (unconfigured_state) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "remote unconfigured-state: %s", unconfigured_state); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "remote unconfigured-state: %s", + unconfigured_state); goto out; } - if (!ostree_repo_get_remote_option (self, pull_data->remote_name, - "custom-backend", NULL, - &custom_backend, - error)) + if (!ostree_repo_get_remote_option (self, pull_data->remote_name, "custom-backend", NULL, + &custom_backend, error)) goto out; if (custom_backend) @@ -4027,8 +3783,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, { if (!_signapi_init_for_remote (pull_data->repo, pull_data->remote_name, &pull_data->signapi_commit_verifiers, - &pull_data->signapi_summary_verifiers, - error)) + &pull_data->signapi_summary_verifiers, error)) goto out; } @@ -4038,32 +3793,28 @@ ostree_repo_pull_with_options (OstreeRepo *self, goto out; pull_data->tmpdir_dfd = pull_data->repo->tmp_dir_fd; - requested_refs_to_fetch = g_hash_table_new_full (ostree_collection_ref_hash, - ostree_collection_ref_equal, - (GDestroyNotify) ostree_collection_ref_free, - g_free); + requested_refs_to_fetch + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, + (GDestroyNotify)ostree_collection_ref_free, g_free); commits_to_fetch = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - if (!ostree_repo_get_remote_option (self, - remote_name_or_baseurl, "metalink", - NULL, &metalink_url_str, error)) + if (!ostree_repo_get_remote_option (self, remote_name_or_baseurl, "metalink", NULL, + &metalink_url_str, error)) goto out; if (!metalink_url_str) { - if (!compute_effective_mirrorlist (self, remote_name_or_baseurl, - url_override, - pull_data->fetcher, - pull_data->n_network_retries, - &pull_data->meta_mirrorlist, - cancellable, error)) + if (!compute_effective_mirrorlist (self, remote_name_or_baseurl, url_override, + pull_data->fetcher, pull_data->n_network_retries, + &pull_data->meta_mirrorlist, cancellable, error)) goto out; } else { - g_autoptr(GBytes) summary_bytes = NULL; - g_autoptr(OstreeFetcherURI) metalink_uri = _ostree_fetcher_uri_parse (metalink_url_str, error); - g_autoptr(OstreeFetcherURI) target_uri = NULL; + g_autoptr (GBytes) summary_bytes = NULL; + g_autoptr (OstreeFetcherURI) metalink_uri + = _ostree_fetcher_uri_parse (metalink_url_str, error); + g_autoptr (OstreeFetcherURI) target_uri = NULL; if (!metalink_uri) goto out; @@ -4072,15 +3823,11 @@ ostree_repo_pull_with_options (OstreeRepo *self, * re-downloads here. Would require additional support for caching the * metalink file or mirror list. */ - metalink = _ostree_metalink_new (pull_data->fetcher, "summary", - OSTREE_MAX_METADATA_SIZE, metalink_uri, - pull_data->n_network_retries); + metalink = _ostree_metalink_new (pull_data->fetcher, "summary", OSTREE_MAX_METADATA_SIZE, + metalink_uri, pull_data->n_network_retries); - if (! _ostree_metalink_request_sync (metalink, - &target_uri, - &summary_bytes, - cancellable, - error)) + if (!_ostree_metalink_request_sync (metalink, &target_uri, &summary_bytes, cancellable, + error)) goto out; /* XXX: would be interesting to implement metalink as another source of @@ -4089,14 +3836,15 @@ ostree_repo_pull_with_options (OstreeRepo *self, { g_autofree char *path = _ostree_fetcher_uri_get_path (target_uri); g_autofree char *basepath = g_path_get_dirname (path); - g_autoptr(OstreeFetcherURI) new_target_uri = _ostree_fetcher_uri_new_path (target_uri, basepath); - pull_data->meta_mirrorlist = - g_ptr_array_new_with_free_func ((GDestroyNotify) _ostree_fetcher_uri_free); + g_autoptr (OstreeFetcherURI) new_target_uri + = _ostree_fetcher_uri_new_path (target_uri, basepath); + pull_data->meta_mirrorlist + = g_ptr_array_new_with_free_func ((GDestroyNotify)_ostree_fetcher_uri_free); g_ptr_array_add (pull_data->meta_mirrorlist, g_steal_pointer (&new_target_uri)); } - pull_data->summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, - summary_bytes, FALSE); + pull_data->summary + = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, summary_bytes, FALSE); } { @@ -4104,31 +3852,25 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (metalink_url_str == NULL && url_override != NULL) contenturl = g_strdup (url_override); - else if (!ostree_repo_get_remote_option (self, remote_name_or_baseurl, - "contenturl", NULL, + else if (!ostree_repo_get_remote_option (self, remote_name_or_baseurl, "contenturl", NULL, &contenturl, error)) goto out; if (contenturl == NULL) { - pull_data->content_mirrorlist = - g_ptr_array_ref (pull_data->meta_mirrorlist); + pull_data->content_mirrorlist = g_ptr_array_ref (pull_data->meta_mirrorlist); } else { - if (!compute_effective_mirrorlist (self, remote_name_or_baseurl, - contenturl, - pull_data->fetcher, - pull_data->n_network_retries, - &pull_data->content_mirrorlist, - cancellable, error)) + if (!compute_effective_mirrorlist (self, remote_name_or_baseurl, contenturl, + pull_data->fetcher, pull_data->n_network_retries, + &pull_data->content_mirrorlist, cancellable, error)) goto out; } } /* FIXME: Do we want an analogue of this which supports collection IDs? */ - if (!ostree_repo_get_remote_list_option (self, - remote_name_or_baseurl, "branches", + if (!ostree_repo_get_remote_list_option (self, remote_name_or_baseurl, "branches", &configured_branches, error)) goto out; @@ -4146,7 +3888,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (g_str_equal (first_scheme, "file") && !pull_data->require_static_deltas) { g_autofree char *uri = _ostree_fetcher_uri_to_string (first_uri); - g_autoptr(GFile) remote_repo_path = g_file_new_for_uri (uri); + g_autoptr (GFile) remote_repo_path = g_file_new_for_uri (uri); pull_data->remote_repo_local = ostree_repo_new (remote_repo_path); if (!ostree_repo_open (pull_data->remote_repo_local, cancellable, error)) goto out; @@ -4185,16 +3927,17 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (flags & OSTREE_REPO_PULL_FLAGS_TRUSTED_HTTP) pull_data->importflags |= _OSTREE_REPO_IMPORT_FLAGS_TRUSTED; - const gboolean verifying_bareuseronly = - (pull_data->importflags & _OSTREE_REPO_IMPORT_FLAGS_VERIFY_BAREUSERONLY) > 0; + const gboolean verifying_bareuseronly + = (pull_data->importflags & _OSTREE_REPO_IMPORT_FLAGS_VERIFY_BAREUSERONLY) > 0; /* If we're mirroring and writing into an archive repo, and both checksum and * bareuseronly are turned off, we can directly copy the content rather than * paying the cost of exploding it, checksumming, and re-gzip. */ - const gboolean mirroring_into_archive = - pull_data->is_mirror && pull_data->repo->mode == OSTREE_REPO_MODE_ARCHIVE; - const gboolean import_trusted = !verifying_bareuseronly && - (pull_data->importflags & _OSTREE_REPO_IMPORT_FLAGS_TRUSTED) > 0; + const gboolean mirroring_into_archive + = pull_data->is_mirror && pull_data->repo->mode == OSTREE_REPO_MODE_ARCHIVE; + const gboolean import_trusted + = !verifying_bareuseronly + && (pull_data->importflags & _OSTREE_REPO_IMPORT_FLAGS_TRUSTED) > 0; pull_data->trusted_http_direct = mirroring_into_archive && import_trusted; } @@ -4225,7 +3968,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, { const gchar *collection_id, *ref_name, *checksum; - while (g_variant_iter_loop (collection_refs_iter, "(&s&s&s)", &collection_id, &ref_name, &checksum)) + while (g_variant_iter_loop (collection_refs_iter, "(&s&s&s)", &collection_id, &ref_name, + &checksum)) { if (!ostree_validate_rev (ref_name, error)) goto out; @@ -4270,22 +4014,24 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (!(branches_iter && *branches_iter)) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "No configured branches for remote %s", remote_name_or_baseurl); + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No configured branches for remote %s", + remote_name_or_baseurl); goto out; } - for (;branches_iter && *branches_iter; branches_iter++) + for (; branches_iter && *branches_iter; branches_iter++) { const char *branch = *branches_iter; - g_hash_table_insert (requested_refs_to_fetch, - ostree_collection_ref_new (NULL, branch), NULL); + g_hash_table_insert (requested_refs_to_fetch, ostree_collection_ref_new (NULL, branch), + NULL); } } /* Deltas are necessary when mirroring or resolving a requested ref to a commit. * We try to avoid loading the potentially large summary if it is not needed. */ - need_summary = require_summary_for_mirror || !all_requested_refs_have_commit (requested_refs_to_fetch) || summary_sig_bytes_v != NULL; + need_summary = require_summary_for_mirror + || !all_requested_refs_have_commit (requested_refs_to_fetch) + || summary_sig_bytes_v != NULL; /* If we don't have indexed deltas, we need the summary for deltas, so check * the config file for support. @@ -4302,20 +4048,21 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (!pull_data->has_indexed_deltas) need_summary = TRUE; - } + } - pull_data->static_delta_superblocks = g_ptr_array_new_with_free_func ((GDestroyNotify)g_variant_unref); + pull_data->static_delta_superblocks + = g_ptr_array_new_with_free_func ((GDestroyNotify)g_variant_unref); if (need_summary) { - g_autoptr(GBytes) bytes_sig = NULL; + g_autoptr (GBytes) bytes_sig = NULL; gboolean summary_sig_not_modified = FALSE; g_autofree char *summary_sig_etag = NULL; guint64 summary_sig_last_modified = 0; gsize n; - g_autoptr(GVariant) refs = NULL; - g_autoptr(GVariant) deltas = NULL; - g_autoptr(GVariant) additional_metadata = NULL; + g_autoptr (GVariant) refs = NULL; + g_autoptr (GVariant) deltas = NULL; + g_autoptr (GVariant) additional_metadata = NULL; gboolean summary_from_cache = FALSE; gboolean tombstone_commits = FALSE; @@ -4346,19 +4093,17 @@ ostree_repo_pull_with_options (OstreeRepo *self, * Last-Modified from the on-disk cache (if it exists) to reduce the * download size if nothing’s changed. */ _ostree_repo_load_cache_summary_properties (self, remote_name_or_baseurl, ".sig", - &summary_sig_if_none_match, &summary_sig_if_modified_since); + &summary_sig_if_none_match, + &summary_sig_if_modified_since); g_clear_pointer (&summary_sig_etag, g_free); summary_sig_last_modified = 0; - if (!_ostree_fetcher_mirrored_request_to_membuf (pull_data->fetcher, - pull_data->meta_mirrorlist, - "summary.sig", OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - summary_sig_if_none_match, summary_sig_if_modified_since, - pull_data->n_network_retries, - &bytes_sig, - &summary_sig_not_modified, &summary_sig_etag, &summary_sig_last_modified, - OSTREE_MAX_METADATA_SIZE, - cancellable, error)) + if (!_ostree_fetcher_mirrored_request_to_membuf ( + pull_data->fetcher, pull_data->meta_mirrorlist, "summary.sig", + OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, summary_sig_if_none_match, + summary_sig_if_modified_since, pull_data->n_network_retries, &bytes_sig, + &summary_sig_not_modified, &summary_sig_etag, &summary_sig_last_modified, + OSTREE_MAX_METADATA_SIZE, cancellable, error)) goto out; /* The server returned HTTP status 304 Not Modified, so we’re clear to @@ -4369,28 +4114,19 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_clear_pointer (&bytes_sig, g_bytes_unref); g_clear_pointer (&bytes_summary, g_bytes_unref); if (!_ostree_repo_load_cache_summary_file (self, remote_name_or_baseurl, ".sig", - &bytes_sig, - cancellable, error)) + &bytes_sig, cancellable, error)) goto out; - if (!bytes_summary && - !pull_data->remote_repo_local && - !_ostree_repo_load_cache_summary_file (self, remote_name_or_baseurl, NULL, - &bytes_summary, - cancellable, error)) + if (!bytes_summary && !pull_data->remote_repo_local + && !_ostree_repo_load_cache_summary_file (self, remote_name_or_baseurl, NULL, + &bytes_summary, cancellable, error)) goto out; } } - if (bytes_sig && - !bytes_summary && - !pull_data->remote_repo_local && - !_ostree_repo_load_cache_summary_if_same_sig (self, - remote_name_or_baseurl, - bytes_sig, - &bytes_summary, - cancellable, - error)) + if (bytes_sig && !bytes_summary && !pull_data->remote_repo_local + && !_ostree_repo_load_cache_summary_if_same_sig (self, remote_name_or_baseurl, bytes_sig, + &bytes_summary, cancellable, error)) goto out; if (bytes_summary && !summary_bytes_v) @@ -4405,20 +4141,18 @@ ostree_repo_pull_with_options (OstreeRepo *self, guint64 summary_if_modified_since = 0; _ostree_repo_load_cache_summary_properties (self, remote_name_or_baseurl, NULL, - &summary_if_none_match, &summary_if_modified_since); + &summary_if_none_match, + &summary_if_modified_since); g_clear_pointer (&summary_etag, g_free); summary_last_modified = 0; - if (!_ostree_fetcher_mirrored_request_to_membuf (pull_data->fetcher, - pull_data->meta_mirrorlist, - "summary", OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - summary_if_none_match, summary_if_modified_since, - pull_data->n_network_retries, - &bytes_summary, - &summary_not_modified, &summary_etag, &summary_last_modified, - OSTREE_MAX_METADATA_SIZE, - cancellable, error)) + if (!_ostree_fetcher_mirrored_request_to_membuf ( + pull_data->fetcher, pull_data->meta_mirrorlist, "summary", + OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, summary_if_none_match, + summary_if_modified_since, pull_data->n_network_retries, &bytes_summary, + &summary_not_modified, &summary_etag, &summary_last_modified, + OSTREE_MAX_METADATA_SIZE, cancellable, error)) goto out; /* The server returned HTTP status 304 Not Modified, so we’re clear to @@ -4427,8 +4161,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, { g_clear_pointer (&bytes_summary, g_bytes_unref); if (!_ostree_repo_load_cache_summary_file (self, remote_name_or_baseurl, NULL, - &bytes_summary, - cancellable, error)) + &bytes_summary, cancellable, error)) goto out; } } @@ -4437,7 +4170,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (!bytes_summary && pull_data->gpg_verify_summary) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "GPG verification enabled, but no summary found (use gpg-verify-summary=false in remote config to disable)"); + "GPG verification enabled, but no summary found (use " + "gpg-verify-summary=false in remote config to disable)"); goto out; } #endif /* OSTREE_DISABLE_GPGME */ @@ -4445,7 +4179,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (!bytes_summary && require_summary_for_mirror) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Fetching all refs was requested in mirror mode, but remote repository does not have a summary"); + "Fetching all refs was requested in mirror mode, but remote repository " + "does not have a summary"); goto out; } @@ -4453,18 +4188,18 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (!bytes_sig && pull_data->gpg_verify_summary) { g_set_error (error, OSTREE_GPG_ERROR, OSTREE_GPG_ERROR_NO_SIGNATURE, - "GPG verification enabled, but no summary.sig found (use gpg-verify-summary=false in remote config to disable)"); + "GPG verification enabled, but no summary.sig found (use " + "gpg-verify-summary=false in remote config to disable)"); goto out; } if (pull_data->gpg_verify_summary && bytes_summary && bytes_sig) { - g_autoptr(OstreeGpgVerifyResult) result = NULL; - g_autoptr(GError) temp_error = NULL; + g_autoptr (OstreeGpgVerifyResult) result = NULL; + g_autoptr (GError) temp_error = NULL; - result = ostree_repo_verify_summary (self, pull_data->remote_name, - bytes_summary, bytes_sig, - cancellable, &temp_error); + result = ostree_repo_verify_summary (self, pull_data->remote_name, bytes_summary, + bytes_sig, cancellable, &temp_error); if (!ostree_gpg_verify_result_require_valid_signature (result, &temp_error)) { if (summary_from_cache) @@ -4488,22 +4223,16 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_clear_pointer (&bytes_summary, g_bytes_unref); g_clear_pointer (&summary_etag, g_free); summary_last_modified = 0; - if (!_ostree_fetcher_mirrored_request_to_membuf (pull_data->fetcher, - pull_data->meta_mirrorlist, - "summary", - OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - NULL, 0, /* no cache headers */ - pull_data->n_network_retries, - &bytes_summary, - &summary_not_modified, &summary_etag, &summary_last_modified, - OSTREE_MAX_METADATA_SIZE, - cancellable, error)) + if (!_ostree_fetcher_mirrored_request_to_membuf ( + pull_data->fetcher, pull_data->meta_mirrorlist, "summary", + OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, NULL, 0, /* no cache headers */ + pull_data->n_network_retries, &bytes_summary, &summary_not_modified, + &summary_etag, &summary_last_modified, OSTREE_MAX_METADATA_SIZE, + cancellable, error)) goto out; - g_autoptr(OstreeGpgVerifyResult) retry = - ostree_repo_verify_summary (self, pull_data->remote_name, - bytes_summary, bytes_sig, - cancellable, error); + g_autoptr (OstreeGpgVerifyResult) retry = ostree_repo_verify_summary ( + self, pull_data->remote_name, bytes_summary, bytes_sig, cancellable, error); if (!ostree_gpg_verify_result_require_valid_signature (retry, error)) goto out; } @@ -4521,19 +4250,21 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (!bytes_sig && pull_data->signapi_summary_verifiers) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Signatures verification enabled, but no summary.sig found (use sign-verify-summary=false in remote config to disable)"); + "Signatures verification enabled, but no summary.sig found (use " + "sign-verify-summary=false in remote config to disable)"); goto out; } if (bytes_summary && bytes_sig) { - g_autoptr(GVariant) signatures = NULL; - g_autoptr(GError) temp_error = NULL; + g_autoptr (GVariant) signatures = NULL; + g_autoptr (GError) temp_error = NULL; - signatures = g_variant_new_from_bytes (OSTREE_SUMMARY_SIG_GVARIANT_FORMAT, - bytes_sig, FALSE); + signatures + = g_variant_new_from_bytes (OSTREE_SUMMARY_SIG_GVARIANT_FORMAT, bytes_sig, FALSE); g_assert (pull_data->signapi_summary_verifiers); - if (!_sign_verify_for_remote (pull_data->signapi_summary_verifiers, bytes_summary, signatures, NULL, &temp_error)) + if (!_sign_verify_for_remote (pull_data->signapi_summary_verifiers, bytes_summary, + signatures, NULL, &temp_error)) { if (summary_from_cache) { @@ -4556,19 +4287,17 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_clear_pointer (&bytes_summary, g_bytes_unref); g_clear_pointer (&summary_etag, g_free); summary_last_modified = 0; - if (!_ostree_fetcher_mirrored_request_to_membuf (pull_data->fetcher, - pull_data->meta_mirrorlist, - "summary", - OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - NULL, 0, /* no cache headers */ - pull_data->n_network_retries, - &bytes_summary, - &summary_not_modified, &summary_etag, &summary_last_modified, - OSTREE_MAX_METADATA_SIZE, - cancellable, error)) + if (!_ostree_fetcher_mirrored_request_to_membuf ( + pull_data->fetcher, pull_data->meta_mirrorlist, "summary", + OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, NULL, + 0, /* no cache headers */ + pull_data->n_network_retries, &bytes_summary, &summary_not_modified, + &summary_etag, &summary_last_modified, OSTREE_MAX_METADATA_SIZE, + cancellable, error)) goto out; - if (!_sign_verify_for_remote (pull_data->signapi_summary_verifiers, bytes_summary, signatures, NULL, error)) + if (!_sign_verify_for_remote (pull_data->signapi_summary_verifiers, + bytes_summary, signatures, NULL, error)) goto out; } else @@ -4585,18 +4314,17 @@ ostree_repo_pull_with_options (OstreeRepo *self, pull_data->summary_data = g_bytes_ref (bytes_summary); pull_data->summary_etag = g_strdup (summary_etag); pull_data->summary_last_modified = summary_last_modified; - pull_data->summary = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, bytes_summary, FALSE); + pull_data->summary + = g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, bytes_summary, FALSE); if (!g_variant_is_normal_form (pull_data->summary)) { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Not normal form"); + g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Not normal form"); goto out; } if (!g_variant_is_of_type (pull_data->summary, OSTREE_SUMMARY_GVARIANT_FORMAT)) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Doesn't match variant type '%s'", + g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Doesn't match variant type '%s'", (char *)OSTREE_SUMMARY_GVARIANT_FORMAT); goto out; } @@ -4611,15 +4339,10 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (!summary_from_cache && bytes_summary && bytes_sig && summary_sig_bytes_v == NULL) { - if (!pull_data->remote_repo_local && - !_ostree_repo_cache_summary (self, - remote_name_or_baseurl, - bytes_summary, - summary_etag, summary_last_modified, - bytes_sig, - summary_sig_etag, summary_sig_last_modified, - cancellable, - error)) + if (!pull_data->remote_repo_local + && !_ostree_repo_cache_summary ( + self, remote_name_or_baseurl, bytes_summary, summary_etag, summary_last_modified, + bytes_sig, summary_sig_etag, summary_sig_last_modified, cancellable, error)) goto out; } @@ -4627,7 +4350,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, { additional_metadata = g_variant_get_child_value (pull_data->summary, 1); - if (!g_variant_lookup (additional_metadata, OSTREE_SUMMARY_COLLECTION_ID, "&s", &main_collection_id)) + if (!g_variant_lookup (additional_metadata, OSTREE_SUMMARY_COLLECTION_ID, "&s", + &main_collection_id)) main_collection_id = NULL; else if (!ostree_validate_collection_id (main_collection_id, error)) goto out; @@ -4636,7 +4360,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, for (i = 0, n = g_variant_n_children (refs); i < n; i++) { const char *refname; - g_autoptr(GVariant) ref = g_variant_get_child_value (refs, i); + g_autoptr (GVariant) ref = g_variant_get_child_value (refs, i); g_variant_get_child (ref, 0, "&s", &refname); @@ -4646,21 +4370,25 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (pull_data->is_mirror && !refs_to_fetch && !opt_collection_refs_set) { g_hash_table_insert (requested_refs_to_fetch, - ostree_collection_ref_new (main_collection_id, refname), NULL); + ostree_collection_ref_new (main_collection_id, refname), + NULL); } } - g_autoptr(GVariant) collection_map = NULL; - collection_map = g_variant_lookup_value (additional_metadata, OSTREE_SUMMARY_COLLECTION_MAP, G_VARIANT_TYPE ("a{sa(s(taya{sv}))}")); + g_autoptr (GVariant) collection_map = NULL; + collection_map + = g_variant_lookup_value (additional_metadata, OSTREE_SUMMARY_COLLECTION_MAP, + G_VARIANT_TYPE ("a{sa(s(taya{sv}))}")); if (collection_map != NULL) { GVariantIter collection_map_iter; const char *collection_id; - g_autoptr(GVariant) collection_refs = NULL; + g_autoptr (GVariant) collection_refs = NULL; g_variant_iter_init (&collection_map_iter, collection_map); - while (g_variant_iter_loop (&collection_map_iter, "{&s@a(s(taya{sv}))}", &collection_id, &collection_refs)) + while (g_variant_iter_loop (&collection_map_iter, "{&s@a(s(taya{sv}))}", + &collection_id, &collection_refs)) { if (!ostree_validate_collection_id (collection_id, error)) goto out; @@ -4668,7 +4396,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, for (i = 0, n = g_variant_n_children (collection_refs); i < n; i++) { const char *refname; - g_autoptr(GVariant) ref = g_variant_get_child_value (collection_refs, i); + g_autoptr (GVariant) ref = g_variant_get_child_value (collection_refs, i); g_variant_get_child (ref, 0, "&s", &refname); @@ -4678,23 +4406,27 @@ ostree_repo_pull_with_options (OstreeRepo *self, if (pull_data->is_mirror && !refs_to_fetch && !opt_collection_refs_set) { g_hash_table_insert (requested_refs_to_fetch, - ostree_collection_ref_new (collection_id, refname), NULL); + ostree_collection_ref_new (collection_id, refname), + NULL); } } } } - deltas = g_variant_lookup_value (additional_metadata, OSTREE_SUMMARY_STATIC_DELTAS, G_VARIANT_TYPE ("a{sv}")); + deltas = g_variant_lookup_value (additional_metadata, OSTREE_SUMMARY_STATIC_DELTAS, + G_VARIANT_TYPE ("a{sv}")); pull_data->summary_has_deltas = deltas != NULL && g_variant_n_children (deltas) > 0; if (!collect_available_deltas_for_pull (pull_data, deltas, error)) goto out; - g_variant_lookup (additional_metadata, OSTREE_SUMMARY_INDEXED_DELTAS, "b", &pull_data->has_indexed_deltas); + g_variant_lookup (additional_metadata, OSTREE_SUMMARY_INDEXED_DELTAS, "b", + &pull_data->has_indexed_deltas); } - if (pull_data->summary && - g_variant_lookup (additional_metadata, OSTREE_SUMMARY_MODE, "s", &remote_mode_str) && - g_variant_lookup (additional_metadata, OSTREE_SUMMARY_TOMBSTONE_COMMITS, "b", &tombstone_commits)) + if (pull_data->summary + && g_variant_lookup (additional_metadata, OSTREE_SUMMARY_MODE, "s", &remote_mode_str) + && g_variant_lookup (additional_metadata, OSTREE_SUMMARY_TOMBSTONE_COMMITS, "b", + &tombstone_commits)) { if (!ostree_repo_mode_from_string (remote_mode_str, &pull_data->remote_mode, error)) goto out; @@ -4703,58 +4435,59 @@ ostree_repo_pull_with_options (OstreeRepo *self, } } - if (pull_data->require_static_deltas && !pull_data->has_indexed_deltas && !pull_data->summary_has_deltas) + if (pull_data->require_static_deltas && !pull_data->has_indexed_deltas + && !pull_data->summary_has_deltas) { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, - "Fetch configured to require static deltas, but no summary deltas or delta index found"); + g_set_error ( + error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, + "Fetch configured to require static deltas, but no summary deltas or delta index found"); goto out; } if (remote_mode_loaded && pull_data->remote_repo_local == NULL) - { - /* Fall-back path which loads the necessary config from the remote’s - * `config` file (unless we already read it above). Doing so is deprecated since it means an - * additional round trip to the remote for each pull. No need to do - * it for local pulls. */ - if (remote_config == NULL && - !load_remote_repo_config (pull_data, &remote_config, cancellable, error)) - goto out; + { + /* Fall-back path which loads the necessary config from the remote’s + * `config` file (unless we already read it above). Doing so is deprecated since it means an + * additional round trip to the remote for each pull. No need to do + * it for local pulls. */ + if (remote_config == NULL + && !load_remote_repo_config (pull_data, &remote_config, cancellable, error)) + goto out; - g_clear_pointer (&remote_mode_str, g_free); - if (!ot_keyfile_get_value_with_default (remote_config, "core", "mode", "bare", - &remote_mode_str, error)) - goto out; + g_clear_pointer (&remote_mode_str, g_free); + if (!ot_keyfile_get_value_with_default (remote_config, "core", "mode", "bare", + &remote_mode_str, error)) + goto out; - if (!ostree_repo_mode_from_string (remote_mode_str, &pull_data->remote_mode, error)) - goto out; + if (!ostree_repo_mode_from_string (remote_mode_str, &pull_data->remote_mode, error)) + goto out; - if (!ot_keyfile_get_boolean_with_default (remote_config, "core", "tombstone-commits", FALSE, - &pull_data->has_tombstone_commits, error)) - goto out; + if (!ot_keyfile_get_boolean_with_default (remote_config, "core", "tombstone-commits", FALSE, + &pull_data->has_tombstone_commits, error)) + goto out; - remote_mode_loaded = TRUE; - } + remote_mode_loaded = TRUE; + } - if (remote_mode_loaded && pull_data->remote_repo_local == NULL && pull_data->remote_mode != OSTREE_REPO_MODE_ARCHIVE) + if (remote_mode_loaded && pull_data->remote_repo_local == NULL + && pull_data->remote_mode != OSTREE_REPO_MODE_ARCHIVE) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Can't pull from archives with mode \"%s\"", - remote_mode_str); + "Can't pull from archives with mode \"%s\"", remote_mode_str); goto out; } /* Resolve the checksum for each ref. This has to be done into a new hash table, * since we can’t modify the keys of @requested_refs_to_fetch while iterating * over it, and we need to ensure the collection IDs are resolved too. */ - updated_requested_refs_to_fetch = g_hash_table_new_full (ostree_collection_ref_hash, - ostree_collection_ref_equal, - (GDestroyNotify) ostree_collection_ref_free, - g_free); - GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef*, ref, - const char*, override_commitid) + updated_requested_refs_to_fetch + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, + (GDestroyNotify)ostree_collection_ref_free, g_free); + GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef *, ref, + const char *, override_commitid) { g_autofree char *checksum = NULL; - g_autoptr(OstreeCollectionRef) ref_with_collection = NULL; + g_autoptr (OstreeCollectionRef) ref_with_collection = NULL; /* Support specifying "" for an override commitid */ if (override_commitid && *override_commitid) @@ -4770,18 +4503,21 @@ ostree_repo_pull_with_options (OstreeRepo *self, guint64 *malloced_size; g_autofree gchar *collection_id = NULL; - if (!lookup_commit_checksum_and_collection_from_summary (pull_data, ref, &checksum, &commit_size, &collection_id, error)) + if (!lookup_commit_checksum_and_collection_from_summary ( + pull_data, ref, &checksum, &commit_size, &collection_id, error)) goto out; ref_with_collection = ostree_collection_ref_new (collection_id, ref->ref_name); malloced_size = g_new0 (guint64, 1); *malloced_size = commit_size; - g_hash_table_insert (pull_data->expected_commit_sizes, g_strdup (checksum), malloced_size); + g_hash_table_insert (pull_data->expected_commit_sizes, g_strdup (checksum), + malloced_size); } else { - if (!fetch_ref_contents (pull_data, main_collection_id, ref, &checksum, cancellable, error)) + if (!fetch_ref_contents (pull_data, main_collection_id, ref, &checksum, cancellable, + error)) goto out; ref_with_collection = ostree_collection_ref_dup (ref); @@ -4806,14 +4542,13 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_steal_pointer (&from_rev)); } - g_hash_table_replace (updated_requested_refs_to_fetch, - g_steal_pointer (&ref_with_collection), + g_hash_table_replace (updated_requested_refs_to_fetch, g_steal_pointer (&ref_with_collection), g_steal_pointer (&checksum)); } /* Resolve refs to a checksum if necessary */ - if (pull_data->timestamp_check_from_rev && - !ostree_validate_checksum_string (pull_data->timestamp_check_from_rev, NULL)) + if (pull_data->timestamp_check_from_rev + && !ostree_validate_checksum_string (pull_data->timestamp_check_from_rev, NULL)) { g_autofree char *from_rev = NULL; if (!ostree_repo_resolve_rev (pull_data->repo, pull_data->timestamp_check_from_rev, FALSE, @@ -4827,8 +4562,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, requested_refs_to_fetch = g_steal_pointer (&updated_requested_refs_to_fetch); if (g_hash_table_size (requested_refs_to_fetch) == 1) { - GLNX_HASH_TABLE_FOREACH (requested_refs_to_fetch, - const OstreeCollectionRef *, ref) + GLNX_HASH_TABLE_FOREACH (requested_refs_to_fetch, const OstreeCollectionRef *, ref) { the_ref_to_fetch = ref->ref_name; break; @@ -4839,9 +4573,10 @@ ostree_repo_pull_with_options (OstreeRepo *self, { const gchar *collection_id, *ref_name, *keyring_remote_name; - while (g_variant_iter_loop (ref_keyring_map_iter, "(&s&s&s)", &collection_id, &ref_name, &keyring_remote_name)) + while (g_variant_iter_loop (ref_keyring_map_iter, "(&s&s&s)", &collection_id, &ref_name, + &keyring_remote_name)) { - g_autoptr(OstreeCollectionRef) c_r = NULL; + g_autoptr (OstreeCollectionRef) c_r = NULL; if (!ostree_validate_collection_id (collection_id, error)) goto out; @@ -4853,8 +4588,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, c_r = ostree_collection_ref_new (collection_id, ref_name); if (!g_hash_table_contains (requested_refs_to_fetch, c_r)) continue; - g_hash_table_insert (pull_data->ref_keyring_map, - g_steal_pointer (&c_r), + g_hash_table_insert (pull_data->ref_keyring_map, g_steal_pointer (&c_r), g_strdup (keyring_remote_name)); } } @@ -4880,24 +4614,24 @@ ostree_repo_pull_with_options (OstreeRepo *self, goto out; pull_data->legacy_transaction_resuming = FALSE; - if (!inherit_transaction && - !ostree_repo_prepare_transaction (pull_data->repo, &pull_data->legacy_transaction_resuming, - cancellable, error)) + if (!inherit_transaction + && !ostree_repo_prepare_transaction (pull_data->repo, &pull_data->legacy_transaction_resuming, + cancellable, error)) goto out; if (pull_data->legacy_transaction_resuming) g_debug ("resuming legacy transaction"); /* Initiate requests for explicit commit revisions */ - GLNX_HASH_TABLE_FOREACH_V (commits_to_fetch, const char*, commit) + GLNX_HASH_TABLE_FOREACH_V (commits_to_fetch, const char *, commit) { if (!initiate_request (pull_data, NULL, commit, error)) goto out; } /* Initiate requests for refs */ - GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef*, ref, - const char*, to_revision) + GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef *, ref, + const char *, to_revision) { if (!initiate_request (pull_data, ref, to_revision, error)) goto out; @@ -4934,8 +4668,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_assert_cmpint (pull_data->n_outstanding_content_fetches, ==, 0); g_assert_cmpint (pull_data->n_outstanding_content_write_requests, ==, 0); - GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef*, ref, - const char*, checksum) + GLNX_HASH_TABLE_FOREACH_KV (requested_refs_to_fetch, const OstreeCollectionRef *, ref, + const char *, checksum) { g_autofree char *remote_ref = NULL; g_autofree char *original_rev = NULL; @@ -4954,46 +4688,44 @@ ostree_repo_pull_with_options (OstreeRepo *self, else { if (pull_data->is_mirror) - ostree_repo_transaction_set_collection_ref (pull_data->repo, - ref, checksum); + ostree_repo_transaction_set_collection_ref (pull_data->repo, ref, checksum); else - ostree_repo_transaction_set_ref (pull_data->repo, - pull_data->remote_refspec_name ?: pull_data->remote_name, - ref->ref_name, checksum); + ostree_repo_transaction_set_ref ( + pull_data->repo, pull_data->remote_refspec_name ?: pull_data->remote_name, + ref->ref_name, checksum); } } - if (pull_data->is_mirror && pull_data->summary_data && - !refs_to_fetch && !opt_collection_refs_set && !configured_branches) + if (pull_data->is_mirror && pull_data->summary_data && !refs_to_fetch && !opt_collection_refs_set + && !configured_branches) { - GLnxFileReplaceFlags replaceflag = - pull_data->repo->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : 0; + GLnxFileReplaceFlags replaceflag + = pull_data->repo->disable_fsync ? GLNX_FILE_REPLACE_NODATASYNC : 0; gsize len; const guint8 *buf = g_bytes_get_data (pull_data->summary_data, &len); - if (!glnx_file_replace_contents_at (pull_data->repo->repo_dir_fd, "summary", - buf, len, replaceflag, - cancellable, error)) + if (!glnx_file_replace_contents_at (pull_data->repo->repo_dir_fd, "summary", buf, len, + replaceflag, cancellable, error)) goto out; - store_file_cache_properties (pull_data->repo->repo_dir_fd, "summary", - pull_data->summary_etag, pull_data->summary_last_modified); + store_file_cache_properties (pull_data->repo->repo_dir_fd, "summary", pull_data->summary_etag, + pull_data->summary_last_modified); if (pull_data->summary_data_sig) { buf = g_bytes_get_data (pull_data->summary_data_sig, &len); - if (!glnx_file_replace_contents_at (pull_data->repo->repo_dir_fd, "summary.sig", - buf, len, replaceflag, - cancellable, error)) + if (!glnx_file_replace_contents_at (pull_data->repo->repo_dir_fd, "summary.sig", buf, len, + replaceflag, cancellable, error)) goto out; store_file_cache_properties (pull_data->repo->repo_dir_fd, "summary.sig", - pull_data->summary_sig_etag, pull_data->summary_sig_last_modified); + pull_data->summary_sig_etag, + pull_data->summary_sig_last_modified); } } - if (!inherit_transaction && - !ostree_repo_commit_transaction (pull_data->repo, &tstats, cancellable, error)) + if (!inherit_transaction + && !ostree_repo_commit_transaction (pull_data->repo, &tstats, cancellable, error)) goto out; end_time = g_get_monotonic_time (); @@ -5001,7 +4733,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, bytes_transferred = _ostree_fetcher_bytes_transferred (pull_data->fetcher); if (pull_data->progress) { - g_autoptr(GString) buf = g_string_new (""); + g_autoptr (GString) buf = g_string_new (""); /* Ensure the rest of the progress keys are set appropriately. */ update_progress (pull_data); @@ -5017,10 +4749,9 @@ ostree_repo_pull_with_options (OstreeRepo *self, else g_string_append_printf (buf, "%u metadata, %u content objects fetched", pull_data->n_fetched_metadata, pull_data->n_fetched_content); - if (!pull_data->remote_repo_local && - (pull_data->n_imported_metadata || pull_data->n_imported_content)) - g_string_append_printf (buf, " (%u meta, %u content local)", - pull_data->n_imported_metadata, + if (!pull_data->remote_repo_local + && (pull_data->n_imported_metadata || pull_data->n_imported_content)) + g_string_append_printf (buf, " (%u meta, %u content local)", pull_data->n_imported_metadata, pull_data->n_imported_content); if (bytes_transferred > 0) @@ -5031,9 +4762,8 @@ ostree_repo_pull_with_options (OstreeRepo *self, else shift = 1024; g_string_append_printf (buf, "; %" G_GUINT64_FORMAT " %s transferred in %u seconds", - (guint64)(bytes_transferred / shift), - shift == 1 ? "B" : "KiB", - (guint) ((end_time - pull_data->start_time) / G_USEC_PER_SEC)); + (guint64)(bytes_transferred / shift), shift == 1 ? "B" : "KiB", + (guint)((end_time - pull_data->start_time) / G_USEC_PER_SEC)); } if (!inherit_transaction) { @@ -5047,13 +4777,14 @@ ostree_repo_pull_with_options (OstreeRepo *self, #ifdef HAVE_LIBSYSTEMD if (bytes_transferred > 0 && pull_data->remote_name) { - g_autoptr(GString) msg = g_string_new (""); + g_autoptr (GString) msg = g_string_new (""); if (the_ref_to_fetch) g_string_append_printf (msg, "libostree pull from '%s' for %s complete", pull_data->remote_name, the_ref_to_fetch); else g_string_append_printf (msg, "libostree pull from '%s' for %u refs complete", - pull_data->remote_name, g_hash_table_size (requested_refs_to_fetch)); + pull_data->remote_name, + g_hash_table_size (requested_refs_to_fetch)); const char *gpg_verify_state; #ifndef OSTREE_DISABLE_GPGME @@ -5097,13 +4828,12 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_string_append (msg, "\n"); if (pull_data->n_fetched_deltaparts > 0) - g_string_append_printf (msg, "delta: parts: %u loose: %u", - pull_data->n_fetched_deltaparts, + g_string_append_printf (msg, "delta: parts: %u loose: %u", pull_data->n_fetched_deltaparts, pull_data->n_fetched_metadata + pull_data->n_fetched_content); else g_string_append_printf (msg, "non-delta: meta: %u content: %u", pull_data->n_fetched_metadata, pull_data->n_fetched_content); - const guint n_seconds = (guint) ((end_time - pull_data->start_time) / G_USEC_PER_SEC); + const guint n_seconds = (guint)((end_time - pull_data->start_time) / G_USEC_PER_SEC); g_autofree char *formatted_xferred = g_format_size (bytes_transferred); g_string_append_printf (msg, "\ntransfer: secs: %u size: %s", n_seconds, formatted_xferred); if (pull_data->signapi_commit_verifiers) @@ -5111,34 +4841,31 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_assert_cmpuint (g_hash_table_size (pull_data->signapi_verified_commits), >, 0); } - ot_journal_send ("MESSAGE=%s", msg->str, - "MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(OSTREE_MESSAGE_FETCH_COMPLETE_ID), - "OSTREE_REMOTE=%s", pull_data->remote_name, - "OSTREE_SIGN=%s", sign_verify_state, - "OSTREE_GPG=%s", gpg_verify_state, - "OSTREE_SECONDS=%u", n_seconds, - "OSTREE_XFER_SIZE=%s", formatted_xferred, - NULL); + ot_journal_send ("MESSAGE=%s", msg->str, "MESSAGE_ID=" SD_ID128_FORMAT_STR, + SD_ID128_FORMAT_VAL (OSTREE_MESSAGE_FETCH_COMPLETE_ID), "OSTREE_REMOTE=%s", + pull_data->remote_name, "OSTREE_SIGN=%s", sign_verify_state, "OSTREE_GPG=%s", + gpg_verify_state, "OSTREE_SECONDS=%u", n_seconds, "OSTREE_XFER_SIZE=%s", + formatted_xferred, NULL); } #endif /* iterate over commits fetched and delete any commitpartial files */ if (pull_data->dirs == NULL && !pull_data->is_commit_only) { - GLNX_HASH_TABLE_FOREACH_V (requested_refs_to_fetch, const char*, checksum) + GLNX_HASH_TABLE_FOREACH_V (requested_refs_to_fetch, const char *, checksum) { if (!ostree_repo_mark_commit_partial (pull_data->repo, checksum, FALSE, error)) goto out; } - GLNX_HASH_TABLE_FOREACH_V (commits_to_fetch, const char*, commit) + GLNX_HASH_TABLE_FOREACH_V (commits_to_fetch, const char *, commit) { if (!ostree_repo_mark_commit_partial (pull_data->repo, commit, FALSE, error)) goto out; } /* and finally any parent commits we might also have pulled because of depth>0 */ - GLNX_HASH_TABLE_FOREACH (pull_data->commit_to_depth, const char*, commit) + GLNX_HASH_TABLE_FOREACH (pull_data->commit_to_depth, const char *, commit) { if (!ostree_repo_mark_commit_partial (pull_data->repo, commit, FALSE, error)) goto out; @@ -5146,7 +4873,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, } ret = TRUE; - out: +out: /* This is pretty ugly - we have two error locations, because we * have a mix of synchronous and async code. Mixing them gets messy * as we need to avoid overwriting errors. @@ -5198,7 +4925,7 @@ ostree_repo_pull_with_options (OstreeRepo *self, g_clear_pointer (&pull_data->pending_fetch_delta_indexes, g_hash_table_unref); g_clear_pointer (&pull_data->pending_fetch_delta_superblocks, g_hash_table_unref); g_clear_pointer (&pull_data->pending_fetch_deltaparts, g_hash_table_unref); - g_queue_foreach (&pull_data->scan_object_queue, (GFunc) scan_object_queue_data_free, NULL); + g_queue_foreach (&pull_data->scan_object_queue, (GFunc)scan_object_queue_data_free, NULL); g_queue_clear (&pull_data->scan_object_queue); g_clear_pointer (&pull_data->idle_src, g_source_destroy); g_clear_pointer (&pull_data->dirs, g_ptr_array_unref); @@ -5212,11 +4939,12 @@ ostree_repo_pull_with_options (OstreeRepo *self, * have refs pointing to this commit. */ typedef struct { - gchar *checksum; /* always set */ - guint64 commit_size; /* always set */ - guint64 timestamp; /* 0 for unknown */ + gchar *checksum; /* always set */ + guint64 commit_size; /* always set */ + guint64 timestamp; /* 0 for unknown */ GVariant *additional_metadata; - GArray *refs; /* (element-type gsize), indexes to refs which point to this commit on at least one remote */ + GArray *refs; /* (element-type gsize), indexes to refs which point to this commit on at least one + remote */ } CommitMetadata; static void @@ -5231,18 +4959,17 @@ commit_metadata_free (CommitMetadata *info) G_DEFINE_AUTOPTR_CLEANUP_FUNC (CommitMetadata, commit_metadata_free) static CommitMetadata * -commit_metadata_new (const gchar *checksum, - guint64 commit_size, - guint64 timestamp, - GVariant *additional_metadata) +commit_metadata_new (const gchar *checksum, guint64 commit_size, guint64 timestamp, + GVariant *additional_metadata) { - g_autoptr(CommitMetadata) info = NULL; + g_autoptr (CommitMetadata) info = NULL; info = g_new0 (CommitMetadata, 1); info->checksum = g_strdup (checksum); info->commit_size = commit_size; info->timestamp = timestamp; - info->additional_metadata = (additional_metadata != NULL) ? g_variant_ref (additional_metadata) : NULL; + info->additional_metadata + = (additional_metadata != NULL) ? g_variant_ref (additional_metadata) : NULL; info->refs = g_array_new (FALSE, FALSE, sizeof (gsize)); return g_steal_pointer (&info); @@ -5254,9 +4981,9 @@ commit_metadata_new (const gchar *checksum, * there. */ typedef struct { - gsize width; /* pointers */ - gsize height; /* pointers */ - gconstpointer pointers[]; /* n_pointers = width * height */ + gsize width; /* pointers */ + gsize height; /* pointers */ + gconstpointer pointers[]; /* n_pointers = width * height */ } PointerTable; static void @@ -5269,14 +4996,14 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (PointerTable, pointer_table_free) /* Both dimensions are in numbers of pointers. */ static PointerTable * -pointer_table_new (gsize width, - gsize height) +pointer_table_new (gsize width, gsize height) { - g_autoptr(PointerTable) table = NULL; + g_autoptr (PointerTable) table = NULL; g_return_val_if_fail (width > 0, NULL); g_return_val_if_fail (height > 0, NULL); - g_return_val_if_fail (width <= (G_MAXSIZE - sizeof (PointerTable)) / sizeof (gconstpointer) / height, NULL); + g_return_val_if_fail ( + width <= (G_MAXSIZE - sizeof (PointerTable)) / sizeof (gconstpointer) / height, NULL); table = g_malloc0 (sizeof (PointerTable) + sizeof (gconstpointer) * width * height); table->width = width; @@ -5286,9 +5013,7 @@ pointer_table_new (gsize width, } static gconstpointer -pointer_table_get (const PointerTable *table, - gsize x, - gsize y) +pointer_table_get (const PointerTable *table, gsize x, gsize y) { g_return_val_if_fail (table != NULL, FALSE); g_return_val_if_fail (x < table->width, FALSE); @@ -5298,10 +5023,7 @@ pointer_table_get (const PointerTable *table, } static void -pointer_table_set (PointerTable *table, - gsize x, - gsize y, - gconstpointer value) +pointer_table_set (PointerTable *table, gsize x, gsize y, gconstpointer value) { g_return_if_fail (table != NULL); g_return_if_fail (x < table->width); @@ -5314,15 +5036,14 @@ pointer_table_set (PointerTable *table, static gboolean is_valid_collection_ref (const OstreeCollectionRef *ref) { - return (ref != NULL && - ostree_validate_rev (ref->ref_name, NULL) && - ostree_validate_collection_id (ref->collection_id, NULL)); + return (ref != NULL && ostree_validate_rev (ref->ref_name, NULL) + && ostree_validate_collection_id (ref->collection_id, NULL)); } /* Validate @refs is non-%NULL, non-empty, and contains only valid collection * and ref names. */ static gboolean -is_valid_collection_ref_array (const OstreeCollectionRef * const *refs) +is_valid_collection_ref_array (const OstreeCollectionRef *const *refs) { gsize i; @@ -5382,19 +5103,18 @@ find_remotes_data_free (FindRemotesData *data) G_DEFINE_AUTOPTR_CLEANUP_FUNC (FindRemotesData, find_remotes_data_free) static FindRemotesData * -find_remotes_data_new (const OstreeCollectionRef * const *refs, - GVariant *options, - OstreeAsyncProgress *progress, - OstreeRepoFinder *default_finder_avahi, - guint n_network_retries) +find_remotes_data_new (const OstreeCollectionRef *const *refs, GVariant *options, + OstreeAsyncProgress *progress, OstreeRepoFinder *default_finder_avahi, + guint n_network_retries) { - g_autoptr(FindRemotesData) data = NULL; + g_autoptr (FindRemotesData) data = NULL; data = g_new0 (FindRemotesData, 1); data->refs = ostree_collection_ref_dupv (refs); data->options = (options != NULL) ? g_variant_ref (options) : NULL; data->progress = (progress != NULL) ? g_object_ref (progress) : NULL; - data->default_finder_avahi = (default_finder_avahi != NULL) ? g_object_ref (default_finder_avahi) : NULL; + data->default_finder_avahi + = (default_finder_avahi != NULL) ? g_object_ref (default_finder_avahi) : NULL; data->n_network_retries = n_network_retries; return g_steal_pointer (&data); @@ -5403,7 +5123,7 @@ find_remotes_data_new (const OstreeCollectionRef * const *refs, static gchar * uint64_secs_to_iso8601 (guint64 secs) { - g_autoptr(GDateTime) dt = g_date_time_new_from_unix_utc (secs); + g_autoptr (GDateTime) dt = g_date_time_new_from_unix_utc (secs); if (dt != NULL) return g_date_time_format (dt, "%FT%TZ"); @@ -5412,11 +5132,10 @@ uint64_secs_to_iso8601 (guint64 secs) } static gint -sort_results_cb (gconstpointer a, - gconstpointer b) +sort_results_cb (gconstpointer a, gconstpointer b) { - const OstreeRepoFinderResult **result_a = (const OstreeRepoFinderResult **) a; - const OstreeRepoFinderResult **result_b = (const OstreeRepoFinderResult **) b; + const OstreeRepoFinderResult **result_a = (const OstreeRepoFinderResult **)a; + const OstreeRepoFinderResult **result_b = (const OstreeRepoFinderResult **)b; return ostree_repo_finder_result_compare (*result_a, *result_b); } @@ -5430,9 +5149,7 @@ repo_finder_result_free0 (OstreeRepoFinderResult *result) ostree_repo_finder_result_free (result); } -static void find_remotes_cb (GObject *obj, - GAsyncResult *result, - gpointer user_data); +static void find_remotes_cb (GObject *obj, GAsyncResult *result, gpointer user_data); /** * ostree_repo_find_remotes_async: @@ -5491,38 +5208,36 @@ static void find_remotes_cb (GObject *obj, * Since: 2018.6 */ void -ostree_repo_find_remotes_async (OstreeRepo *self, - const OstreeCollectionRef * const *refs, - GVariant *options, - OstreeRepoFinder **finders, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +ostree_repo_find_remotes_async (OstreeRepo *self, const OstreeCollectionRef *const *refs, + GVariant *options, OstreeRepoFinder **finders, + OstreeAsyncProgress *progress, GCancellable *cancellable, + GAsyncReadyCallback callback, gpointer user_data) { - g_autoptr(GTask) task = NULL; - g_autoptr(FindRemotesData) data = NULL; - OstreeRepoFinder *default_finders[4] = { NULL, }; - g_autoptr(OstreeRepoFinder) finder_config = NULL; - g_autoptr(OstreeRepoFinder) finder_mount = NULL; - g_autoptr(OstreeRepoFinder) finder_avahi = NULL; + g_autoptr (GTask) task = NULL; + g_autoptr (FindRemotesData) data = NULL; + OstreeRepoFinder *default_finders[4] = { + NULL, + }; + g_autoptr (OstreeRepoFinder) finder_config = NULL; + g_autoptr (OstreeRepoFinder) finder_mount = NULL; + g_autoptr (OstreeRepoFinder) finder_avahi = NULL; g_autofree char **override_commit_ids = NULL; guint n_network_retries = DEFAULT_N_NETWORK_RETRIES; g_return_if_fail (OSTREE_IS_REPO (self)); g_return_if_fail (is_valid_collection_ref_array (refs)); - g_return_if_fail (options == NULL || - g_variant_is_of_type (options, G_VARIANT_TYPE_VARDICT)); + g_return_if_fail (options == NULL || g_variant_is_of_type (options, G_VARIANT_TYPE_VARDICT)); g_return_if_fail (finders == NULL || is_valid_finder_array (finders)); g_return_if_fail (progress == NULL || OSTREE_IS_ASYNC_PROGRESS (progress)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); if (options) { - (void) g_variant_lookup (options, "override-commit-ids", "^a&s", &override_commit_ids); - g_return_if_fail (override_commit_ids == NULL || g_strv_length ((gchar **) refs) == g_strv_length (override_commit_ids)); + (void)g_variant_lookup (options, "override-commit-ids", "^a&s", &override_commit_ids); + g_return_if_fail (override_commit_ids == NULL + || g_strv_length ((gchar **)refs) == g_strv_length (override_commit_ids)); - (void) g_variant_lookup (options, "n-network-retries", "u", &n_network_retries); + (void)g_variant_lookup (options, "n-network-retries", "u", &n_network_retries); } /* Set up a task for the whole operation. */ @@ -5536,22 +5251,25 @@ ostree_repo_find_remotes_async (OstreeRepo *self, #ifdef HAVE_AVAHI guint avahi_index; GMainContext *context = g_main_context_get_thread_default (); - g_autoptr(GError) local_error = NULL; -#endif /* HAVE_AVAHI */ + g_autoptr (GError) local_error = NULL; +#endif /* HAVE_AVAHI */ - if (g_strv_contains ((const char * const *)self->repo_finders, "config")) - default_finders[finder_index++] = finder_config = OSTREE_REPO_FINDER (ostree_repo_finder_config_new ()); + if (g_strv_contains ((const char *const *)self->repo_finders, "config")) + default_finders[finder_index++] = finder_config + = OSTREE_REPO_FINDER (ostree_repo_finder_config_new ()); - if (g_strv_contains ((const char * const *)self->repo_finders, "mount")) - default_finders[finder_index++] = finder_mount = OSTREE_REPO_FINDER (ostree_repo_finder_mount_new (NULL)); + if (g_strv_contains ((const char *const *)self->repo_finders, "mount")) + default_finders[finder_index++] = finder_mount + = OSTREE_REPO_FINDER (ostree_repo_finder_mount_new (NULL)); #ifdef HAVE_AVAHI - if (g_strv_contains ((const char * const *)self->repo_finders, "lan")) + if (g_strv_contains ((const char *const *)self->repo_finders, "lan")) { avahi_index = finder_index; - default_finders[finder_index++] = finder_avahi = OSTREE_REPO_FINDER (ostree_repo_finder_avahi_new (context)); + default_finders[finder_index++] = finder_avahi + = OSTREE_REPO_FINDER (ostree_repo_finder_avahi_new (context)); } -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ /* self->repo_finders is guaranteed to be non-empty */ g_assert (default_finders != NULL); @@ -5560,8 +5278,7 @@ ostree_repo_find_remotes_async (OstreeRepo *self, #ifdef HAVE_AVAHI if (finder_avahi != NULL) { - ostree_repo_finder_avahi_start (OSTREE_REPO_FINDER_AVAHI (finder_avahi), - &local_error); + ostree_repo_finder_avahi_start (OSTREE_REPO_FINDER_AVAHI (finder_avahi), &local_error); if (local_error != NULL) { @@ -5575,7 +5292,8 @@ ostree_repo_find_remotes_async (OstreeRepo *self, * would cause client code to abort if a warning were emitted. */ if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) - g_debug ("Avahi finder failed under normal operation; removing it: %s", local_error->message); + g_debug ("Avahi finder failed under normal operation; removing it: %s", + local_error->message); else g_warning ("Avahi finder failed abnormally; removing it: %s", local_error->message); @@ -5583,34 +5301,32 @@ ostree_repo_find_remotes_async (OstreeRepo *self, g_clear_object (&finder_avahi); } } -#endif /* HAVE_AVAHI */ +#endif /* HAVE_AVAHI */ } /* We need to keep a pointer to the default Avahi finder so we can stop it * again after the operation, which happens implicitly by dropping the final * ref. */ data = find_remotes_data_new (refs, options, progress, finder_avahi, n_network_retries); - g_task_set_task_data (task, g_steal_pointer (&data), (GDestroyNotify) find_remotes_data_free); + g_task_set_task_data (task, g_steal_pointer (&data), (GDestroyNotify)find_remotes_data_free); /* Asynchronously resolve all possible remotes for the given refs. */ - ostree_repo_finder_resolve_all_async (finders, refs, self, cancellable, - find_remotes_cb, g_steal_pointer (&task)); + ostree_repo_finder_resolve_all_async (finders, refs, self, cancellable, find_remotes_cb, + g_steal_pointer (&task)); } /* Find the first instance of (@collection_id, @ref_name) in @refs and return * its index; or return %FALSE if nothing’s found. */ static gboolean -collection_refv_contains (const OstreeCollectionRef * const *refs, - const gchar *collection_id, - const gchar *ref_name, - gsize *out_index) +collection_refv_contains (const OstreeCollectionRef *const *refs, const gchar *collection_id, + const gchar *ref_name, gsize *out_index) { gsize i; for (i = 0; refs[i] != NULL; i++) { - if (g_str_equal (refs[i]->collection_id, collection_id) && - g_str_equal (refs[i]->ref_name, ref_name)) + if (g_str_equal (refs[i]->collection_id, collection_id) + && g_str_equal (refs[i]->ref_name, ref_name)) { *out_index = i; return TRUE; @@ -5625,26 +5341,23 @@ collection_refv_contains (const OstreeCollectionRef * const *refs, * points to into @refs_and_remotes_table at (@ref_index, @result_index). * @ref_index is the ref’s index in @refs. */ static gboolean -find_remotes_process_refs (OstreeRepo *self, - const OstreeCollectionRef * const *refs, - OstreeRepoFinderResult *result, - gsize result_index, - const gchar *summary_collection_id, - GVariant *summary_refs, - GHashTable *commit_metadatas, - PointerTable *refs_and_remotes_table) +find_remotes_process_refs (OstreeRepo *self, const OstreeCollectionRef *const *refs, + OstreeRepoFinderResult *result, gsize result_index, + const gchar *summary_collection_id, GVariant *summary_refs, + GHashTable *commit_metadatas, PointerTable *refs_and_remotes_table) { gsize j, n; for (j = 0, n = g_variant_n_children (summary_refs); j < n; j++) { const guchar *csum_bytes; - g_autoptr(GVariant) ref_v = NULL, csum_v = NULL, commit_metadata_v = NULL, stored_commit_v = NULL; + g_autoptr (GVariant) ref_v = NULL, csum_v = NULL, commit_metadata_v = NULL, + stored_commit_v = NULL; guint64 commit_size, commit_timestamp; gchar tmp_checksum[OSTREE_SHA256_STRING_LEN + 1]; gsize ref_index; - g_autoptr(GDateTime) dt = NULL; - g_autoptr(GError) error = NULL; + g_autoptr (GDateTime) dt = NULL; + g_autoptr (GError) error = NULL; const gchar *ref_name; CommitMetadata *commit_metadata; @@ -5654,8 +5367,8 @@ find_remotes_process_refs (OstreeRepo *self, if (!ostree_validate_rev (ref_name, &error)) { - g_debug ("%s: Summary for result ‘%s’ contained invalid ref name ‘%s’: %s", - G_STRFUNC, result->remote->name, ref_name, error->message); + g_debug ("%s: Summary for result ‘%s’ contained invalid ref name ‘%s’: %s", G_STRFUNC, + result->remote->name, ref_name, error->message); return FALSE; } @@ -5665,8 +5378,8 @@ find_remotes_process_refs (OstreeRepo *self, csum_bytes = ostree_checksum_bytes_peek_validate (csum_v, &error); if (csum_bytes == NULL) { - g_debug ("%s: Summary for result ‘%s’ contained invalid ref checksum: %s", - G_STRFUNC, result->remote->name, error->message); + g_debug ("%s: Summary for result ‘%s’ contained invalid ref checksum: %s", G_STRFUNC, + result->remote->name, error->message); return FALSE; } @@ -5682,7 +5395,7 @@ find_remotes_process_refs (OstreeRepo *self, /* Check the additional metadata. */ if (!g_variant_lookup (commit_metadata_v, OSTREE_COMMIT_TIMESTAMP, "t", &commit_timestamp)) - commit_timestamp = 0; /* unknown */ + commit_timestamp = 0; /* unknown */ else commit_timestamp = GUINT64_FROM_BE (commit_timestamp); @@ -5690,7 +5403,8 @@ find_remotes_process_refs (OstreeRepo *self, if (dt == NULL) { - g_debug ("%s: Summary for result ‘%s’ contained commit timestamp %" G_GUINT64_FORMAT " which is too far in the future. Resetting to 0.", + g_debug ("%s: Summary for result ‘%s’ contained commit timestamp %" G_GUINT64_FORMAT + " which is too far in the future. Resetting to 0.", G_STRFUNC, result->remote->name, commit_timestamp); commit_timestamp = 0; } @@ -5700,11 +5414,11 @@ find_remotes_process_refs (OstreeRepo *self, if (commit_metadata == NULL) { - commit_metadata = commit_metadata_new (tmp_checksum, commit_size, - (stored_commit_v != NULL) ? ostree_commit_get_timestamp (stored_commit_v) : 0, - NULL); + commit_metadata = commit_metadata_new ( + tmp_checksum, commit_size, + (stored_commit_v != NULL) ? ostree_commit_get_timestamp (stored_commit_v) : 0, NULL); g_hash_table_insert (commit_metadatas, commit_metadata->checksum, - commit_metadata /* transfer */); + commit_metadata /* transfer */); } /* Update the metadata if possible. */ @@ -5714,59 +5428,63 @@ find_remotes_process_refs (OstreeRepo *self, } else if (commit_timestamp != 0 && commit_metadata->timestamp != commit_timestamp) { - g_debug ("%s: Summary for result ‘%s’ contained commit timestamp %" G_GUINT64_FORMAT " which did not match existing timestamp %" G_GUINT64_FORMAT ". Ignoring.", + g_debug ("%s: Summary for result ‘%s’ contained commit timestamp %" G_GUINT64_FORMAT + " which did not match existing timestamp %" G_GUINT64_FORMAT ". Ignoring.", G_STRFUNC, result->remote->name, commit_timestamp, commit_metadata->timestamp); return FALSE; } if (commit_size != commit_metadata->commit_size) { - g_debug ("%s: Summary for result ‘%s’ contained commit size %" G_GUINT64_FORMAT "B which did not match existing size %" G_GUINT64_FORMAT "B. Ignoring.", + g_debug ("%s: Summary for result ‘%s’ contained commit size %" G_GUINT64_FORMAT + "B which did not match existing size %" G_GUINT64_FORMAT "B. Ignoring.", G_STRFUNC, result->remote->name, commit_size, commit_metadata->commit_size); return FALSE; } - pointer_table_set (refs_and_remotes_table, ref_index, result_index, commit_metadata->checksum); + pointer_table_set (refs_and_remotes_table, ref_index, result_index, + commit_metadata->checksum); g_array_append_val (commit_metadata->refs, ref_index); - g_debug ("%s: Remote ‘%s’ lists ref ‘%s’ mapping to commit ‘%s’.", - G_STRFUNC, result->remote->name, ref_name, commit_metadata->checksum); + g_debug ("%s: Remote ‘%s’ lists ref ‘%s’ mapping to commit ‘%s’.", G_STRFUNC, + result->remote->name, ref_name, commit_metadata->checksum); } return TRUE; } static void -find_remotes_cb (GObject *obj, - GAsyncResult *async_result, - gpointer user_data) +find_remotes_cb (GObject *obj, GAsyncResult *async_result, gpointer user_data) { OstreeRepo *self; - g_autoptr(GTask) task = NULL; + g_autoptr (GTask) task = NULL; GCancellable *cancellable; const FindRemotesData *data; - const OstreeCollectionRef * const *refs; + const OstreeCollectionRef *const *refs; /* FIXME: We currently do nothing with @progress. Comment out to assuage -Wunused-variable */ /* OstreeAsyncProgress *progress; */ - g_autoptr(GError) error = NULL; - g_autoptr(GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ + g_autoptr (GError) error = NULL; + g_autoptr (GPtrArray) results = NULL; /* (element-type OstreeRepoFinderResult) */ gsize i; - g_autoptr(PointerTable) refs_and_remotes_table = NULL; /* (element-type commit-checksum) */ - 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) */ + g_autoptr (PointerTable) refs_and_remotes_table = NULL; /* (element-type commit-checksum) */ + 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) */ - g_autoptr(GPtrArray) final_results = NULL; /* (element-type OstreeRepoFinderResult) */ + g_autoptr (GPtrArray) remotes_to_remove = NULL; /* (element-type OstreeRemote) */ + g_autoptr (GPtrArray) final_results = NULL; /* (element-type OstreeRepoFinderResult) */ task = G_TASK (user_data); self = OSTREE_REPO (g_task_get_source_object (task)); cancellable = g_task_get_cancellable (task); data = g_task_get_task_data (task); - refs = (const OstreeCollectionRef * const *) data->refs; + refs = (const OstreeCollectionRef *const *)data->refs; /* progress = data->progress; */ /* Finish finding the remotes. */ @@ -5780,7 +5498,7 @@ find_remotes_cb (GObject *obj, if (results->len == 0) { - g_task_return_pointer (task, g_steal_pointer (&results), (GDestroyNotify) g_ptr_array_unref); + g_task_return_pointer (task, g_steal_pointer (&results), (GDestroyNotify)g_ptr_array_unref); return; } @@ -5788,11 +5506,11 @@ find_remotes_cb (GObject *obj, * clearing them to %NULL. We cannot remove them from the array, as that messes * up iteration and stored array indices. Accordingly, we need the free function * to be %NULL-safe. */ - g_ptr_array_set_free_func (results, (GDestroyNotify) repo_finder_result_free0); + g_ptr_array_set_free_func (results, (GDestroyNotify)repo_finder_result_free0); if (data->options) { - (void) g_variant_lookup (data->options, "override-commit-ids", "^a&s", &override_commit_ids); + (void)g_variant_lookup (data->options, "override-commit-ids", "^a&s", &override_commit_ids); } /* FIXME: In future, we also want to pull static delta superblocks in this @@ -5801,14 +5519,15 @@ find_remotes_cb (GObject *obj, * disable-static-deltas option first. */ /* Each key must be a pointer to the #CommitMetadata.checksum field of its value. */ - commit_metadatas = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify) commit_metadata_free); + commit_metadatas + = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)commit_metadata_free); /* X dimension is an index into @refs. Y dimension is an index into @results. * Each cell stores the commit checksum which that ref resolves to on that * remote, or %NULL if the remote doesn’t have that ref. */ - n_refs = g_strv_length ((gchar **) refs); /* it’s not a GStrv, but this works */ + n_refs = g_strv_length ((gchar **)refs); /* it’s not a GStrv, but this works */ refs_and_remotes_table = pointer_table_new (n_refs, results->len); - remotes_to_remove = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_remote_unref); + remotes_to_remove = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_remote_unref); /* Fetch and validate the summary file for each result. */ /* FIXME: All these downloads could be parallelised; that requires the @@ -5816,13 +5535,13 @@ find_remotes_cb (GObject *obj, for (i = 0; i < results->len; i++) { OstreeRepoFinderResult *result = g_ptr_array_index (results, i); - g_autoptr(GBytes) summary_bytes = NULL; - g_autoptr(GVariant) summary_v = NULL; + g_autoptr (GBytes) summary_bytes = NULL; + g_autoptr (GVariant) summary_v = NULL; guint64 summary_last_modified; - g_autoptr(GVariant) summary_refs = NULL; - g_autoptr(GVariant) additional_metadata_v = NULL; + g_autoptr (GVariant) summary_refs = NULL; + g_autoptr (GVariant) additional_metadata_v = NULL; g_autofree gchar *summary_collection_id = NULL; - g_autoptr(GVariantIter) summary_collection_map = NULL; + g_autoptr (GVariantIter) summary_collection_map = NULL; gboolean invalid_result = FALSE; /* Add the remote to our internal list of remotes, so other libostree @@ -5830,41 +5549,36 @@ find_remotes_cb (GObject *obj, if (!_ostree_repo_add_remote (self, result->remote)) g_ptr_array_add (remotes_to_remove, ostree_remote_ref (result->remote)); - g_debug ("%s: Fetching summary for remote ‘%s’ with keyring ‘%s’.", - G_STRFUNC, result->remote->name, result->remote->keyring); + g_debug ("%s: Fetching summary for remote ‘%s’ with keyring ‘%s’.", G_STRFUNC, + result->remote->name, result->remote->keyring); /* Download the summary. This will load from the cache if possible. */ - ostree_repo_remote_fetch_summary_with_options (self, - result->remote->name, - NULL, /* no options */ - &summary_bytes, - NULL, - cancellable, - &error); + ostree_repo_remote_fetch_summary_with_options (self, result->remote->name, + NULL, /* no options */ + &summary_bytes, NULL, cancellable, &error); if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) goto error; else if (error != NULL) { - g_debug ("%s: Failed to download summary for result ‘%s’. Ignoring. %s", - G_STRFUNC, result->remote->name, error->message); + g_debug ("%s: Failed to download summary for result ‘%s’. Ignoring. %s", G_STRFUNC, + result->remote->name, error->message); g_clear_pointer (&g_ptr_array_index (results, i), ostree_repo_finder_result_free); g_clear_error (&error); continue; } else if (summary_bytes == NULL) { - g_debug ("%s: Failed to download summary for result ‘%s’. Ignoring. %s", - G_STRFUNC, result->remote->name, - "No summary file exists on server"); + g_debug ("%s: Failed to download summary for result ‘%s’. Ignoring. %s", G_STRFUNC, + result->remote->name, "No summary file exists on server"); g_clear_pointer (&g_ptr_array_index (results, i), ostree_repo_finder_result_free); continue; } /* Check the metadata in the summary file, especially whether it contains * all the @refs we are interested in. */ - summary_v = g_variant_ref_sink (g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, - summary_bytes, FALSE)); + summary_v = g_variant_ref_sink ( + g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT, summary_bytes, FALSE)); /* Check the summary’s additional metadata and set up @commit_metadata * and @refs_and_remotes_table with the refs listed in the summary file, @@ -5872,33 +5586,37 @@ find_remotes_cb (GObject *obj, * intersection with @refs. */ additional_metadata_v = g_variant_get_child_value (summary_v, 1); - if (g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_COLLECTION_ID, "s", &summary_collection_id)) + if (g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_COLLECTION_ID, "s", + &summary_collection_id)) { summary_refs = g_variant_get_child_value (summary_v, 0); - if (!find_remotes_process_refs (self, refs, result, i, summary_collection_id, summary_refs, - commit_metadatas, refs_and_remotes_table)) + if (!find_remotes_process_refs (self, refs, result, i, summary_collection_id, + summary_refs, commit_metadatas, refs_and_remotes_table)) { g_clear_pointer (&g_ptr_array_index (results, i), ostree_repo_finder_result_free); continue; } } - if (!g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_COLLECTION_MAP, "a{sa(s(taya{sv}))}", &summary_collection_map)) + if (!g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_COLLECTION_MAP, + "a{sa(s(taya{sv}))}", &summary_collection_map)) summary_collection_map = NULL; - while (summary_collection_map != NULL && - g_variant_iter_loop (summary_collection_map, "{s@a(s(taya{sv}))}", &summary_collection_id, &summary_refs)) + while (summary_collection_map != NULL + && g_variant_iter_loop (summary_collection_map, "{s@a(s(taya{sv}))}", + &summary_collection_id, &summary_refs)) { /* Exclude refs that don't use the associated keyring if this is a * dynamic remote, by comparing against the collection ID of the * remote this one inherits from */ - if (result->remote->refspec_name != NULL && - !check_remote_matches_collection_id (self, result->remote->refspec_name, summary_collection_id)) + if (result->remote->refspec_name != NULL + && !check_remote_matches_collection_id (self, result->remote->refspec_name, + summary_collection_id)) continue; - if (!find_remotes_process_refs (self, refs, result, i, summary_collection_id, summary_refs, - commit_metadatas, refs_and_remotes_table)) + if (!find_remotes_process_refs (self, refs, result, i, summary_collection_id, + summary_refs, commit_metadatas, refs_and_remotes_table)) { g_clear_pointer (&g_ptr_array_index (results, i), ostree_repo_finder_result_free); invalid_result = TRUE; @@ -5910,7 +5628,8 @@ find_remotes_cb (GObject *obj, continue; /* Check the summary timestamp. */ - if (!g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_LAST_MODIFIED, "t", &summary_last_modified)) + if (!g_variant_lookup (additional_metadata_v, OSTREE_SUMMARY_LAST_MODIFIED, "t", + &summary_last_modified)) summary_last_modified = 0; else summary_last_modified = GUINT64_FROM_BE (summary_last_modified); @@ -5927,21 +5646,22 @@ find_remotes_cb (GObject *obj, * the commit metadata from the remotes. The ‘most recent commits’ are the * set of head commits pointed to by the refs we just resolved from the * summary files. */ - GLNX_HASH_TABLE_FOREACH_V (commit_metadatas, CommitMetadata*, commit_metadata) + GLNX_HASH_TABLE_FOREACH_V (commit_metadatas, CommitMetadata *, commit_metadata) { char buf[_OSTREE_LOOSE_PATH_MAX]; g_autofree gchar *commit_filename = NULL; - g_autoptr(GPtrArray) mirrorlist = NULL; /* (element-type OstreeFetcherURI) */ - g_autoptr(GBytes) commit_bytes = NULL; - g_autoptr(GVariant) commit_v = NULL; + g_autoptr (GPtrArray) mirrorlist = NULL; /* (element-type OstreeFetcherURI) */ + g_autoptr (GBytes) commit_bytes = NULL; + g_autoptr (GVariant) commit_v = NULL; guint64 commit_timestamp; - g_autoptr(GDateTime) dt = NULL; + g_autoptr (GDateTime) dt = NULL; /* Already complete? */ if (commit_metadata->timestamp != 0) continue; - _ostree_loose_path (buf, commit_metadata->checksum, OSTREE_OBJECT_TYPE_COMMIT, OSTREE_REPO_MODE_ARCHIVE); + _ostree_loose_path (buf, commit_metadata->checksum, OSTREE_OBJECT_TYPE_COMMIT, + OSTREE_REPO_MODE_ARCHIVE); commit_filename = g_build_filename ("objects", buf, NULL); /* For each of the remotes whose summary files contain this ref, try @@ -5960,52 +5680,44 @@ find_remotes_cb (GObject *obj, if (result == NULL) continue; - if (pointer_table_get (refs_and_remotes_table, ref_index, j) != commit_metadata->checksum) + if (pointer_table_get (refs_and_remotes_table, ref_index, j) + != commit_metadata->checksum) continue; g_autofree gchar *uri = NULL; - g_autoptr(OstreeFetcherURI) fetcher_uri = NULL; + g_autoptr (OstreeFetcherURI) fetcher_uri = NULL; - if (!ostree_repo_remote_get_url (self, result->remote->name, - &uri, &error)) + if (!ostree_repo_remote_get_url (self, result->remote->name, &uri, &error)) goto error; fetcher_uri = _ostree_fetcher_uri_parse (uri, &error); if (fetcher_uri == NULL) goto error; - fetcher = _ostree_repo_remote_new_fetcher (self, result->remote->name, - TRUE, NULL, NULL, NULL, &error); + fetcher = _ostree_repo_remote_new_fetcher (self, result->remote->name, TRUE, NULL, + NULL, NULL, &error); if (fetcher == NULL) goto error; - g_debug ("%s: Fetching metadata for commit ‘%s’ from remote ‘%s’.", - G_STRFUNC, commit_metadata->checksum, result->remote->name); + g_debug ("%s: Fetching metadata for commit ‘%s’ from remote ‘%s’.", G_STRFUNC, + commit_metadata->checksum, result->remote->name); /* FIXME: Support remotes which have contenturl, mirrorlist, etc. */ - mirrorlist = g_ptr_array_new_with_free_func ((GDestroyNotify) _ostree_fetcher_uri_free); + mirrorlist + = g_ptr_array_new_with_free_func ((GDestroyNotify)_ostree_fetcher_uri_free); g_ptr_array_add (mirrorlist, g_steal_pointer (&fetcher_uri)); - if (!_ostree_fetcher_mirrored_request_to_membuf (fetcher, - mirrorlist, - commit_filename, - OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, - NULL, 0, - data->n_network_retries, - &commit_bytes, - NULL, NULL, NULL, - 0, /* no maximum size */ - cancellable, - &error)) + if (!_ostree_fetcher_mirrored_request_to_membuf ( + fetcher, mirrorlist, commit_filename, OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT, + NULL, 0, data->n_network_retries, &commit_bytes, NULL, NULL, NULL, + 0, /* no maximum size */ + cancellable, &error)) goto error; - g_autoptr(OstreeGpgVerifyResult) verify_result = NULL; + g_autoptr (OstreeGpgVerifyResult) verify_result = NULL; - verify_result = ostree_repo_verify_commit_for_remote (self, - commit_metadata->checksum, - result->remote->name, - cancellable, - &error); + verify_result = ostree_repo_verify_commit_for_remote ( + self, commit_metadata->checksum, result->remote->name, cancellable, &error); if (verify_result == NULL) { g_prefix_error (&error, "Commit %s: ", commit_metadata->checksum); @@ -6028,21 +5740,21 @@ find_remotes_cb (GObject *obj, if (commit_bytes == NULL) { - g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED, - "Metadata not found for commit ‘%s’", commit_metadata->checksum); + g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED, "Metadata not found for commit ‘%s’", + commit_metadata->checksum); goto error; } /* Parse the commit metadata. */ - commit_v = g_variant_new_from_bytes (OSTREE_COMMIT_GVARIANT_FORMAT, - commit_bytes, FALSE); + commit_v = g_variant_new_from_bytes (OSTREE_COMMIT_GVARIANT_FORMAT, commit_bytes, FALSE); g_variant_get_child (commit_v, 5, "t", &commit_timestamp); commit_timestamp = GUINT64_FROM_BE (commit_timestamp); dt = g_date_time_new_from_unix_utc (commit_timestamp); if (dt == NULL) { - g_debug ("%s: Commit ‘%s’ metadata contained timestamp %" G_GUINT64_FORMAT " which is too far in the future. Resetting to 0.", + g_debug ("%s: Commit ‘%s’ metadata contained timestamp %" G_GUINT64_FORMAT + " which is too far in the future. Resetting to 0.", G_STRFUNC, commit_metadata->checksum, commit_timestamp); commit_timestamp = 0; } @@ -6075,8 +5787,8 @@ find_remotes_cb (GObject *obj, if (override_commit_ids) { - g_debug ("%s: Using specified commit ‘%s’ for ref (%s, %s).", - G_STRFUNC, override_commit_ids[i], refs[i]->collection_id, refs[i]->ref_name); + g_debug ("%s: Using specified commit ‘%s’ for ref (%s, %s).", G_STRFUNC, + override_commit_ids[i], refs[i]->collection_id, refs[i]->ref_name); continue; } @@ -6093,8 +5805,8 @@ find_remotes_cb (GObject *obj, candidate_commit_metadata = g_hash_table_lookup (commit_metadatas, candidate_checksum); g_assert (candidate_commit_metadata != NULL); - if (latest_commit_metadata == NULL || - candidate_commit_metadata->timestamp > latest_commit_metadata->timestamp) + if (latest_commit_metadata == NULL + || candidate_commit_metadata->timestamp > latest_commit_metadata->timestamp) { latest_checksum = candidate_checksum; latest_commit_metadata = candidate_commit_metadata; @@ -6113,27 +5825,31 @@ find_remotes_cb (GObject *obj, if (latest_commit_metadata != NULL) { latest_commit_timestamp_str = uint64_secs_to_iso8601 (latest_commit_metadata->timestamp); - g_debug ("%s: Latest commit for ref (%s, %s) across all remotes is ‘%s’ with timestamp %s.", - G_STRFUNC, refs[i]->collection_id, refs[i]->ref_name, - latest_checksum, latest_commit_timestamp_str); + g_debug ( + "%s: Latest commit for ref (%s, %s) across all remotes is ‘%s’ with timestamp %s.", + G_STRFUNC, refs[i]->collection_id, refs[i]->ref_name, latest_checksum, + latest_commit_timestamp_str); } else { - g_debug ("%s: Latest commit for ref (%s, %s) is unknown due to failure to download metadata.", - G_STRFUNC, refs[i]->collection_id, refs[i]->ref_name); + g_debug ( + "%s: Latest commit for ref (%s, %s) is unknown due to failure to download metadata.", + G_STRFUNC, refs[i]->collection_id, refs[i]->ref_name); } } /* Recombine @commit_metadatas and @results so that each * #OstreeRepoFinderResult.refs lists the refs for which that remote has the * latest commits (i.e. it’s not out of date compared to some other remote). */ - final_results = g_ptr_array_new_with_free_func ((GDestroyNotify) ostree_repo_finder_result_free); + final_results = g_ptr_array_new_with_free_func ((GDestroyNotify)ostree_repo_finder_result_free); for (i = 0; i < results->len; i++) { 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) */ + 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? */ @@ -6142,15 +5858,13 @@ find_remotes_cb (GObject *obj, /* Map of refs to checksums provided by this result. The checksums should * be %NULL for each ref unless this result provides the latest checksum. */ - validated_ref_to_checksum = g_hash_table_new_full (ostree_collection_ref_hash, - ostree_collection_ref_equal, - (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); + validated_ref_to_checksum + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, + (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++) @@ -6218,7 +5932,7 @@ find_remotes_cb (GObject *obj, _ostree_repo_remove_remote (self, remote); } - g_task_return_pointer (task, g_steal_pointer (&final_results), (GDestroyNotify) g_ptr_array_unref); + g_task_return_pointer (task, g_steal_pointer (&final_results), (GDestroyNotify)g_ptr_array_unref); return; @@ -6248,11 +5962,9 @@ error: * Since: 2018.6 */ OstreeRepoFinderResult ** -ostree_repo_find_remotes_finish (OstreeRepo *self, - GAsyncResult *result, - GError **error) +ostree_repo_find_remotes_finish (OstreeRepo *self, GAsyncResult *result, GError **error) { - g_autoptr(GPtrArray) results = NULL; + g_autoptr (GPtrArray) results = NULL; g_return_val_if_fail (OSTREE_IS_REPO (self), NULL); g_return_val_if_fail (g_task_is_valid (result, self), NULL); @@ -6263,20 +5975,18 @@ ostree_repo_find_remotes_finish (OstreeRepo *self, if (results != NULL) { - g_ptr_array_add (results, NULL); /* NULL terminator */ - return (OstreeRepoFinderResult **) g_ptr_array_free (g_steal_pointer (&results), FALSE); + g_ptr_array_add (results, NULL); /* NULL terminator */ + return (OstreeRepoFinderResult **)g_ptr_array_free (g_steal_pointer (&results), FALSE); } else return NULL; } static void -copy_option (GVariantDict *master_options, - GVariantDict *slave_options, - const gchar *key, +copy_option (GVariantDict *master_options, GVariantDict *slave_options, const gchar *key, const GVariantType *expected_type) { - g_autoptr(GVariant) option_v = g_variant_dict_lookup_value (master_options, key, expected_type); + g_autoptr (GVariant) option_v = g_variant_dict_lookup_value (master_options, key, expected_type); if (option_v != NULL) g_variant_dict_insert_value (slave_options, key, option_v); } @@ -6339,13 +6049,10 @@ copy_option (GVariantDict *master_options, * Since: 2018.6 */ void -ostree_repo_pull_from_remotes_async (OstreeRepo *self, - const OstreeRepoFinderResult * const *results, - GVariant *options, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +ostree_repo_pull_from_remotes_async (OstreeRepo *self, const OstreeRepoFinderResult *const *results, + GVariant *options, OstreeAsyncProgress *progress, + GCancellable *cancellable, GAsyncReadyCallback callback, + gpointer user_data) { g_return_if_fail (OSTREE_IS_REPO (self)); g_return_if_fail (results != NULL && results[0] != NULL); @@ -6353,12 +6060,12 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, g_return_if_fail (progress == NULL || OSTREE_IS_ASYNC_PROGRESS (progress)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); - g_autoptr(GTask) task = NULL; - g_autoptr(GHashTable) refs_pulled = NULL; /* (element-type OstreeCollectionRef gboolean) */ + g_autoptr (GTask) task = NULL; + g_autoptr (GHashTable) refs_pulled = NULL; /* (element-type OstreeCollectionRef gboolean) */ gsize i, j; - g_autoptr(GString) refs_unpulled_string = NULL; - g_autoptr(GError) local_error = NULL; - g_auto(GVariantDict) options_dict = OT_VARIANT_BUILDER_INITIALIZER; + g_autoptr (GString) refs_unpulled_string = NULL; + g_autoptr (GError) local_error = NULL; + g_auto (GVariantDict) options_dict = OT_VARIANT_BUILDER_INITIALIZER; OstreeRepoPullFlags flags; gboolean inherit_transaction; @@ -6368,8 +6075,8 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, /* Keep track of the set of refs we’ve pulled already. Value is %TRUE if the * ref has been pulled; %FALSE if it has not. */ - refs_pulled = g_hash_table_new_full (ostree_collection_ref_hash, - ostree_collection_ref_equal, NULL, NULL); + refs_pulled + = g_hash_table_new_full (ostree_collection_ref_hash, ostree_collection_ref_equal, NULL, NULL); g_variant_dict_init (&options_dict, options); @@ -6379,8 +6086,8 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, inherit_transaction = FALSE; /* Run all the local pull operations in a single overall transaction. */ - if (!inherit_transaction && - !ostree_repo_prepare_transaction (self, NULL, cancellable, &local_error)) + if (!inherit_transaction + && !ostree_repo_prepare_transaction (self, NULL, cancellable, &local_error)) { g_task_return_error (task, g_steal_pointer (&local_error)); return; @@ -6396,31 +6103,30 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, { const OstreeRepoFinderResult *result = results[i]; - g_autoptr(GString) refs_to_pull_str = NULL; - g_autoptr(GPtrArray) refs_to_pull = NULL; /* (element-type OstreeCollectionRef) */ - g_auto(GVariantBuilder) refs_to_pull_builder = OT_VARIANT_BUILDER_INITIALIZER; - g_auto(GVariantDict) local_options_dict = OT_VARIANT_BUILDER_INITIALIZER; - g_autoptr(GVariant) local_options = NULL; + g_autoptr (GString) refs_to_pull_str = NULL; + g_autoptr (GPtrArray) refs_to_pull = NULL; /* (element-type OstreeCollectionRef) */ + g_auto (GVariantBuilder) refs_to_pull_builder = OT_VARIANT_BUILDER_INITIALIZER; + g_auto (GVariantDict) local_options_dict = OT_VARIANT_BUILDER_INITIALIZER; + g_autoptr (GVariant) local_options = NULL; gboolean remove_remote; refs_to_pull = g_ptr_array_new_with_free_func (NULL); refs_to_pull_str = g_string_new (""); g_variant_builder_init (&refs_to_pull_builder, G_VARIANT_TYPE ("a(sss)")); - GLNX_HASH_TABLE_FOREACH_KV (result->ref_to_checksum, const OstreeCollectionRef*, ref, - const char*, checksum) + GLNX_HASH_TABLE_FOREACH_KV (result->ref_to_checksum, const OstreeCollectionRef *, ref, + const char *, checksum) { - if (checksum != NULL && - !GPOINTER_TO_INT (g_hash_table_lookup (refs_pulled, ref))) + if (checksum != NULL && !GPOINTER_TO_INT (g_hash_table_lookup (refs_pulled, ref))) { - g_ptr_array_add (refs_to_pull, (gpointer) ref); - g_variant_builder_add (&refs_to_pull_builder, "(sss)", - ref->collection_id, ref->ref_name, checksum); + g_ptr_array_add (refs_to_pull, (gpointer)ref); + g_variant_builder_add (&refs_to_pull_builder, "(sss)", ref->collection_id, + ref->ref_name, checksum); if (refs_to_pull_str->len > 0) g_string_append (refs_to_pull_str, ", "); - g_string_append_printf (refs_to_pull_str, "(%s, %s)", - ref->collection_id, ref->ref_name); + g_string_append_printf (refs_to_pull_str, "(%s, %s)", ref->collection_id, + ref->ref_name); } } @@ -6435,14 +6141,15 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, /* NULL terminators. */ g_ptr_array_add (refs_to_pull, NULL); - g_debug ("Pulling from remote ‘%s’: %s", - result->remote->name, refs_to_pull_str->str); + g_debug ("Pulling from remote ‘%s’: %s", result->remote->name, refs_to_pull_str->str); /* Set up the pull options. */ g_variant_dict_init (&local_options_dict, NULL); - g_variant_dict_insert (&local_options_dict, "flags", "i", OSTREE_REPO_PULL_FLAGS_UNTRUSTED | flags); - g_variant_dict_insert_value (&local_options_dict, "collection-refs", g_variant_builder_end (&refs_to_pull_builder)); + g_variant_dict_insert (&local_options_dict, "flags", "i", + OSTREE_REPO_PULL_FLAGS_UNTRUSTED | flags); + g_variant_dict_insert_value (&local_options_dict, "collection-refs", + g_variant_builder_end (&refs_to_pull_builder)); #ifndef OSTREE_DISABLE_GPGME g_variant_dict_insert (&local_options_dict, "gpg-verify", "b", TRUE); #else @@ -6453,22 +6160,25 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, g_variant_dict_insert (&local_options_dict, "sign-verify-summary", "b", FALSE); g_variant_dict_insert (&local_options_dict, "inherit-transaction", "b", TRUE); if (result->remote->refspec_name != NULL) - g_variant_dict_insert (&local_options_dict, "override-remote-name", "s", result->remote->refspec_name); + g_variant_dict_insert (&local_options_dict, "override-remote-name", "s", + result->remote->refspec_name); copy_option (&options_dict, &local_options_dict, "depth", G_VARIANT_TYPE ("i")); - copy_option (&options_dict, &local_options_dict, "disable-static-deltas", G_VARIANT_TYPE ("b")); + copy_option (&options_dict, &local_options_dict, "disable-static-deltas", + G_VARIANT_TYPE ("b")); copy_option (&options_dict, &local_options_dict, "http-headers", G_VARIANT_TYPE ("a(ss)")); copy_option (&options_dict, &local_options_dict, "subdirs", G_VARIANT_TYPE ("as")); copy_option (&options_dict, &local_options_dict, "update-frequency", G_VARIANT_TYPE ("u")); copy_option (&options_dict, &local_options_dict, "append-user-agent", G_VARIANT_TYPE ("s")); copy_option (&options_dict, &local_options_dict, "n-network-retries", G_VARIANT_TYPE ("u")); - copy_option (&options_dict, &local_options_dict, "ref-keyring-map", G_VARIANT_TYPE ("a(sss)")); + copy_option (&options_dict, &local_options_dict, "ref-keyring-map", + G_VARIANT_TYPE ("a(sss)")); local_options = g_variant_dict_end (&local_options_dict); /* FIXME: We do nothing useful with @progress at the moment. */ remove_remote = !_ostree_repo_add_remote (self, result->remote); - ostree_repo_pull_with_options (self, result->remote->name, local_options, - progress, cancellable, &local_error); + ostree_repo_pull_with_options (self, result->remote->name, local_options, progress, + cancellable, &local_error); if (remove_remote) _ostree_repo_remove_remote (self, result->remote); @@ -6486,8 +6196,7 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, if (local_error != NULL) { - g_debug ("Failed to pull refs from ‘%s’: %s", - result->remote->name, local_error->message); + g_debug ("Failed to pull refs from ‘%s’: %s", result->remote->name, local_error->message); g_clear_error (&local_error); continue; } @@ -6498,16 +6207,16 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, } /* Commit the transaction. */ - if (!inherit_transaction && - !ostree_repo_commit_transaction (self, NULL, cancellable, &local_error)) + if (!inherit_transaction + && !ostree_repo_commit_transaction (self, NULL, cancellable, &local_error)) { g_task_return_error (task, g_steal_pointer (&local_error)); return; } /* Any refs left un-downloaded? If so, we’ve failed. */ - GLNX_HASH_TABLE_FOREACH_KV (refs_pulled, const OstreeCollectionRef*, ref, - gpointer, is_pulled_pointer) + GLNX_HASH_TABLE_FOREACH_KV (refs_pulled, const OstreeCollectionRef *, ref, gpointer, + is_pulled_pointer) { gboolean is_pulled = GPOINTER_TO_INT (is_pulled_pointer); @@ -6519,8 +6228,7 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, else g_string_append (refs_unpulled_string, ", "); - g_string_append_printf (refs_unpulled_string, "(%s, %s)", - ref->collection_id, ref->ref_name); + g_string_append_printf (refs_unpulled_string, "(%s, %s)", ref->collection_id, ref->ref_name); } if (refs_unpulled_string != NULL) @@ -6547,13 +6255,12 @@ ostree_repo_pull_from_remotes_async (OstreeRepo *self, * Since: 2018.6 */ gboolean -ostree_repo_pull_from_remotes_finish (OstreeRepo *self, - GAsyncResult *result, - GError **error) +ostree_repo_pull_from_remotes_finish (OstreeRepo *self, GAsyncResult *result, GError **error) { g_return_val_if_fail (OSTREE_IS_REPO (self), FALSE); g_return_val_if_fail (g_task_is_valid (result, self), FALSE); - g_return_val_if_fail (g_async_result_is_tagged (result, ostree_repo_pull_from_remotes_async), FALSE); + g_return_val_if_fail (g_async_result_is_tagged (result, ostree_repo_pull_from_remotes_async), + FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); return g_task_propagate_boolean (G_TASK (result), error); @@ -6585,25 +6292,22 @@ ostree_repo_pull_from_remotes_finish (OstreeRepo *self, * Since: 2016.6 */ gboolean -ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, - const char *name, - GVariant *options, - GBytes **out_summary, - GBytes **out_signatures, - GCancellable *cancellable, - GError **error) +ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, const char *name, + GVariant *options, GBytes **out_summary, + GBytes **out_signatures, GCancellable *cancellable, + GError **error) { g_autofree char *metalink_url_string = NULL; - g_autoptr(GBytes) summary = NULL; - g_autoptr(GBytes) signatures = NULL; + g_autoptr (GBytes) summary = NULL; + g_autoptr (GBytes) signatures = NULL; gboolean gpg_verify_summary; - g_autoptr(GPtrArray) signapi_summary_verifiers = NULL; + g_autoptr (GPtrArray) signapi_summary_verifiers = NULL; gboolean summary_is_from_cache = FALSE; - g_autoptr(OstreeFetcher) fetcher = NULL; - g_autoptr(GMainContextPopDefault) mainctx = NULL; + g_autoptr (OstreeFetcher) fetcher = NULL; + g_autoptr (GMainContextPopDefault) mainctx = NULL; const char *url_override = NULL; - g_autoptr(GVariant) extra_headers = NULL; - g_autoptr(GPtrArray) mirrorlist = NULL; + g_autoptr (GVariant) extra_headers = NULL; + g_autoptr (GPtrArray) mirrorlist = NULL; const char *append_user_agent = NULL; guint n_network_retries = DEFAULT_N_NETWORK_RETRIES; gboolean summary_sig_not_modified = FALSE; @@ -6620,44 +6324,40 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, g_return_val_if_fail (OSTREE_REPO (self), FALSE); g_return_val_if_fail (name != NULL, FALSE); - if (!ostree_repo_get_remote_option (self, name, "metalink", NULL, - &metalink_url_string, error)) + if (!ostree_repo_get_remote_option (self, name, "metalink", NULL, &metalink_url_string, error)) return FALSE; if (options) { - (void) g_variant_lookup (options, "override-url", "&s", &url_override); - (void) g_variant_lookup (options, "http-headers", "@a(ss)", &extra_headers); - (void) g_variant_lookup (options, "append-user-agent", "&s", &append_user_agent); - (void) g_variant_lookup (options, "n-network-retries", "u", &n_network_retries); + (void)g_variant_lookup (options, "override-url", "&s", &url_override); + (void)g_variant_lookup (options, "http-headers", "@a(ss)", &extra_headers); + (void)g_variant_lookup (options, "append-user-agent", "&s", &append_user_agent); + (void)g_variant_lookup (options, "n-network-retries", "u", &n_network_retries); } if (!ostree_repo_remote_get_gpg_verify_summary (self, name, &gpg_verify_summary, error)) return FALSE; - if (!_signapi_init_for_remote (self, name, NULL, - &signapi_summary_verifiers, - error)) + if (!_signapi_init_for_remote (self, name, NULL, &signapi_summary_verifiers, error)) return FALSE; mainctx = _ostree_main_context_new_default (); - fetcher = _ostree_repo_remote_new_fetcher (self, name, TRUE, extra_headers, append_user_agent, NULL, error); + fetcher = _ostree_repo_remote_new_fetcher (self, name, TRUE, extra_headers, append_user_agent, + NULL, error); if (fetcher == NULL) return FALSE; if (metalink_url_string) { - g_autoptr(OstreeFetcherURI) uri = _ostree_fetcher_uri_parse (metalink_url_string, error); + g_autoptr (OstreeFetcherURI) uri = _ostree_fetcher_uri_parse (metalink_url_string, error); if (!uri) return FALSE; - mirrorlist = - g_ptr_array_new_with_free_func ((GDestroyNotify) _ostree_fetcher_uri_free); + mirrorlist = g_ptr_array_new_with_free_func ((GDestroyNotify)_ostree_fetcher_uri_free); g_ptr_array_add (mirrorlist, g_steal_pointer (&uri)); } - else if (!compute_effective_mirrorlist (self, name, url_override, - fetcher, n_network_retries, + else if (!compute_effective_mirrorlist (self, name, url_override, fetcher, n_network_retries, &mirrorlist, cancellable, error)) return FALSE; @@ -6666,22 +6366,16 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, * much benefit since summary.sig is typically 590B in size (vs a 0B HTTP 304 * response). But if a repository has multiple keys, the signature file will * grow and this optimisation may be useful. */ - _ostree_repo_load_cache_summary_properties (self, name, ".sig", - &summary_sig_if_none_match, &summary_sig_if_modified_since); - _ostree_repo_load_cache_summary_properties (self, name, NULL, - &summary_if_none_match, &summary_if_modified_since); - - if (!_ostree_preload_metadata_file (self, - fetcher, - mirrorlist, - "summary.sig", - metalink_url_string ? TRUE : FALSE, - summary_sig_if_none_match, summary_sig_if_modified_since, - n_network_retries, - &signatures, - &summary_sig_not_modified, &summary_sig_etag, &summary_sig_last_modified, - cancellable, - error)) + _ostree_repo_load_cache_summary_properties (self, name, ".sig", &summary_sig_if_none_match, + &summary_sig_if_modified_since); + _ostree_repo_load_cache_summary_properties (self, name, NULL, &summary_if_none_match, + &summary_if_modified_since); + + if (!_ostree_preload_metadata_file (self, fetcher, mirrorlist, "summary.sig", + metalink_url_string ? TRUE : FALSE, summary_sig_if_none_match, + summary_sig_if_modified_since, n_network_retries, &signatures, + &summary_sig_not_modified, &summary_sig_etag, + &summary_sig_last_modified, cancellable, error)) return FALSE; /* The server returned HTTP status 304 Not Modified, so we’re clear to @@ -6691,26 +6385,19 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, { g_clear_pointer (&signatures, g_bytes_unref); g_clear_pointer (&summary, g_bytes_unref); - if (!_ostree_repo_load_cache_summary_file (self, name, ".sig", - &signatures, - cancellable, error)) + if (!_ostree_repo_load_cache_summary_file (self, name, ".sig", &signatures, cancellable, + error)) return FALSE; - if (!summary && - !_ostree_repo_load_cache_summary_file (self, name, NULL, - &summary, - cancellable, error)) + if (!summary + && !_ostree_repo_load_cache_summary_file (self, name, NULL, &summary, cancellable, error)) return FALSE; } if (signatures && !summary) { - if (!_ostree_repo_load_cache_summary_if_same_sig (self, - name, - signatures, - &summary, - cancellable, - error)) + if (!_ostree_repo_load_cache_summary_if_same_sig (self, name, signatures, &summary, + cancellable, error)) return FALSE; } @@ -6718,17 +6405,10 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, summary_is_from_cache = TRUE; else { - if (!_ostree_preload_metadata_file (self, - fetcher, - mirrorlist, - "summary", - metalink_url_string ? TRUE : FALSE, - summary_if_none_match, summary_if_modified_since, - n_network_retries, - &summary, - &summary_not_modified, &summary_etag, &summary_last_modified, - cancellable, - error)) + if (!_ostree_preload_metadata_file ( + self, fetcher, mirrorlist, "summary", metalink_url_string ? TRUE : FALSE, + summary_if_none_match, summary_if_modified_since, n_network_retries, &summary, + &summary_not_modified, &summary_etag, &summary_last_modified, cancellable, error)) return FALSE; /* The server returned HTTP status 304 Not Modified, so we’re clear to @@ -6737,31 +6417,23 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, if (summary_not_modified) { g_clear_pointer (&summary, g_bytes_unref); - if (!_ostree_repo_load_cache_summary_file (self, name, NULL, - &summary, - cancellable, error)) + if (!_ostree_repo_load_cache_summary_file (self, name, NULL, &summary, cancellable, + error)) return FALSE; } } - if (!_ostree_repo_verify_summary (self, name, - gpg_verify_summary, signapi_summary_verifiers, - summary, signatures, - cancellable, error)) - return FALSE; + if (!_ostree_repo_verify_summary (self, name, gpg_verify_summary, signapi_summary_verifiers, + summary, signatures, cancellable, error)) + return FALSE; if (!summary_is_from_cache && summary && signatures) { - g_autoptr(GError) temp_error = NULL; + g_autoptr (GError) temp_error = NULL; - if (!_ostree_repo_cache_summary (self, - name, - summary, - summary_etag, summary_last_modified, - signatures, - summary_sig_etag, summary_sig_last_modified, - cancellable, - &temp_error)) + if (!_ostree_repo_cache_summary (self, name, summary, summary_etag, summary_last_modified, + signatures, summary_sig_etag, summary_sig_last_modified, + cancellable, &temp_error)) { if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED)) g_debug ("No permissions to save summary cache"); @@ -6785,55 +6457,46 @@ ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, #else /* HAVE_LIBCURL_OR_LIBSOUP */ gboolean -ostree_repo_pull_with_options (OstreeRepo *self, - const char *remote_name_or_baseurl, - GVariant *options, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GError **error) +ostree_repo_pull_with_options (OstreeRepo *self, const char *remote_name_or_baseurl, + GVariant *options, OstreeAsyncProgress *progress, + GCancellable *cancellable, GError **error) { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); + g_set_error_literal ( + error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, + "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); return FALSE; } gboolean -ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, - const char *name, - GVariant *options, - GBytes **out_summary, - GBytes **out_signatures, - GCancellable *cancellable, - GError **error) +ostree_repo_remote_fetch_summary_with_options (OstreeRepo *self, const char *name, + GVariant *options, GBytes **out_summary, + GBytes **out_signatures, GCancellable *cancellable, + GError **error) { - g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); + g_set_error_literal ( + error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, + "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); return FALSE; } void -ostree_repo_find_remotes_async (OstreeRepo *self, - const OstreeCollectionRef * const *refs, - GVariant *options, - OstreeRepoFinder **finders, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +ostree_repo_find_remotes_async (OstreeRepo *self, const OstreeCollectionRef *const *refs, + GVariant *options, OstreeRepoFinder **finders, + OstreeAsyncProgress *progress, GCancellable *cancellable, + GAsyncReadyCallback callback, gpointer user_data) { g_return_if_fail (OSTREE_IS_REPO (self)); - g_task_report_new_error (self, callback, user_data, ostree_repo_find_remotes_async, - G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); + g_task_report_new_error ( + self, callback, user_data, ostree_repo_find_remotes_async, G_IO_ERROR, + G_IO_ERROR_NOT_SUPPORTED, + "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); } OstreeRepoFinderResult ** -ostree_repo_find_remotes_finish (OstreeRepo *self, - GAsyncResult *result, - GError **error) +ostree_repo_find_remotes_finish (OstreeRepo *self, GAsyncResult *result, GError **error) { - g_autoptr(GPtrArray) results = NULL; + g_autoptr (GPtrArray) results = NULL; g_return_val_if_fail (OSTREE_IS_REPO (self), NULL); g_return_val_if_fail (g_task_is_valid (result, self), NULL); @@ -6846,31 +6509,28 @@ ostree_repo_find_remotes_finish (OstreeRepo *self, } void -ostree_repo_pull_from_remotes_async (OstreeRepo *self, - const OstreeRepoFinderResult * const *results, - GVariant *options, - OstreeAsyncProgress *progress, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) +ostree_repo_pull_from_remotes_async (OstreeRepo *self, const OstreeRepoFinderResult *const *results, + GVariant *options, OstreeAsyncProgress *progress, + GCancellable *cancellable, GAsyncReadyCallback callback, + gpointer user_data) { g_return_if_fail (OSTREE_IS_REPO (self)); - g_task_report_new_error (self, callback, user_data, ostree_repo_find_remotes_async, - G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, - "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); + g_task_report_new_error ( + self, callback, user_data, ostree_repo_find_remotes_async, G_IO_ERROR, + G_IO_ERROR_NOT_SUPPORTED, + "This version of ostree was built without libsoup or libcurl, and cannot fetch over HTTP"); } gboolean -ostree_repo_pull_from_remotes_finish (OstreeRepo *self, - GAsyncResult *result, - GError **error) +ostree_repo_pull_from_remotes_finish (OstreeRepo *self, GAsyncResult *result, GError **error) { gboolean success; g_return_val_if_fail (OSTREE_IS_REPO (self), FALSE); g_return_val_if_fail (g_task_is_valid (result, self), FALSE); - g_return_val_if_fail (g_async_result_is_tagged (result, ostree_repo_pull_from_remotes_async), FALSE); + g_return_val_if_fail (g_async_result_is_tagged (result, ostree_repo_pull_from_remotes_async), + FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); success = g_task_propagate_boolean (G_TASK (result), error); |