From 4dfa7721bb6dce7a588ffd2add13db042759c8a4 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Tue, 17 Jul 2018 10:16:52 -0400 Subject: [PATCH] Remove unused etag functionality Checking the registry against a previous etag is now handled inside flatpak_cache_http_uri(), so remove the etag parameters that were previously passed around in various places for simplicity. Closes: #1910 Approved by: alexlarsson --- app/flatpak-builtins-build-bundle.c | 2 +- app/flatpak-builtins-build-import-bundle.c | 2 +- common/flatpak-dir.c | 5 ++- common/flatpak-oci-registry-private.h | 2 -- common/flatpak-oci-registry.c | 36 ++++------------------ common/flatpak-utils-http-private.h | 2 -- common/flatpak-utils-http.c | 13 -------- common/flatpak-utils.c | 2 +- system-helper/flatpak-system-helper.c | 2 +- 9 files changed, 12 insertions(+), 54 deletions(-) diff --git a/app/flatpak-builtins-build-bundle.c b/app/flatpak-builtins-build-bundle.c index fb636fb6..c4af1d25 100644 --- a/app/flatpak-builtins-build-bundle.c +++ b/app/flatpak-builtins-build-bundle.c @@ -520,7 +520,7 @@ build_oci (OstreeRepo *repo, GFile *dir, flatpak_oci_export_annotations (manifest->annotations, manifest_desc->annotations); - index = flatpak_oci_registry_load_index (registry, NULL, NULL, NULL, NULL); + index = flatpak_oci_registry_load_index (registry, NULL, NULL); if (index == NULL) index = flatpak_oci_index_new (); diff --git a/app/flatpak-builtins-build-import-bundle.c b/app/flatpak-builtins-build-import-bundle.c index 68297619..97968f65 100644 --- a/app/flatpak-builtins-build-import-bundle.c +++ b/app/flatpak-builtins-build-import-bundle.c @@ -71,7 +71,7 @@ import_oci (OstreeRepo *repo, GFile *file, if (registry == NULL) return NULL; - index = flatpak_oci_registry_load_index (registry, NULL, NULL, cancellable, error); + index = flatpak_oci_registry_load_index (registry, cancellable, error); if (index == NULL) return NULL; diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c index 7c49de1a..245d16cc 100644 --- a/common/flatpak-dir.c +++ b/common/flatpak-dir.c @@ -3914,7 +3914,7 @@ flatpak_dir_pull_extra_data (FlatpakDir *self, else { ensure_soup_session (self); - bytes = flatpak_load_http_uri (self->soup_session, extra_data_uri, 0, NULL, NULL, + bytes = flatpak_load_http_uri (self->soup_session, extra_data_uri, 0, extra_data_progress_report, &extra_data_progress, cancellable, error); } @@ -9046,7 +9046,6 @@ flatpak_dir_remote_make_oci_summary (FlatpakDir *self, g_autoptr(GFile) index_cache = NULL; g_autofree char *index_uri = NULL; g_autoptr(GFile) summary_cache = NULL; - g_autofree char *cache_etag = NULL; g_autofree char *self_name = NULL; g_autoptr(GError) local_error = NULL; g_autoptr(GMappedFile) mfile = NULL; @@ -11632,7 +11631,7 @@ flatpak_dir_fetch_remote_object (FlatpakDir *self, object_url = g_build_filename (base_url, "objects", part1, part2, NULL); bytes = flatpak_load_http_uri (self->soup_session, object_url, 0, - NULL, NULL, NULL, NULL, + NULL, NULL, cancellable, error); if (bytes == NULL) return NULL; diff --git a/common/flatpak-oci-registry-private.h b/common/flatpak-oci-registry-private.h index eb767759..e9f22e48 100644 --- a/common/flatpak-oci-registry-private.h +++ b/common/flatpak-oci-registry-private.h @@ -62,8 +62,6 @@ FlatpakOciRegistry * flatpak_oci_registry_new (const char *uri, GError **error); const char * flatpak_oci_registry_get_uri (FlatpakOciRegistry *self); FlatpakOciIndex * flatpak_oci_registry_load_index (FlatpakOciRegistry *self, - const char *etag, - char **etag_out, GCancellable *cancellable, GError **error); gboolean flatpak_oci_registry_save_index (FlatpakOciRegistry *self, diff --git a/common/flatpak-oci-registry.c b/common/flatpak-oci-registry.c index 7a4833fe..9bb15b37 100644 --- a/common/flatpak-oci-registry.c +++ b/common/flatpak-oci-registry.c @@ -268,36 +268,21 @@ local_open_file (int dfd, static GBytes * local_load_file (int dfd, const char *subpath, - const char *etag, - char **etag_out, GCancellable *cancellable, GError **error) { glnx_autofd int fd = -1; struct stat st_buf; GBytes *bytes; - g_autofree char *current_etag = NULL; fd = local_open_file (dfd, subpath, &st_buf, cancellable, error); if (fd == -1) return NULL; - current_etag = g_strdup_printf ("%lu", st_buf.st_mtime); - - if (etag != NULL && strcmp (current_etag, etag) == 0) - { - g_set_error (error, FLATPAK_OCI_ERROR, FLATPAK_OCI_ERROR_NOT_CHANGED, - "File %s was not changed", subpath); - return NULL; - } - bytes = glnx_fd_readall_bytes (fd, cancellable, error); if (bytes == NULL) return NULL; - if (etag_out) - *etag_out = g_steal_pointer (¤t_etag); - return bytes; } @@ -305,8 +290,6 @@ static GBytes * remote_load_file (SoupSession *soup_session, SoupURI *base, const char *subpath, - const char *etag, - char **etag_out, GCancellable *cancellable, GError **error) { @@ -324,7 +307,7 @@ remote_load_file (SoupSession *soup_session, uri_s = soup_uri_to_string (uri, FALSE); bytes = flatpak_load_http_uri (soup_session, - uri_s, FLATPAK_HTTP_FLAGS_ACCEPT_OCI, etag, etag_out, + uri_s, FLATPAK_HTTP_FLAGS_ACCEPT_OCI, NULL, NULL, cancellable, error); if (bytes == NULL) @@ -336,15 +319,13 @@ remote_load_file (SoupSession *soup_session, static GBytes * flatpak_oci_registry_load_file (FlatpakOciRegistry *self, const char *subpath, - const char *etag, - char **etag_out, GCancellable *cancellable, GError **error) { if (self->dfd != -1) - return local_load_file (self->dfd, subpath, etag, etag_out, cancellable, error); + return local_load_file (self->dfd, subpath, cancellable, error); else - return remote_load_file (self->soup_session, self->base_uri, subpath, etag, etag_out, cancellable, error); + return remote_load_file (self->soup_session, self->base_uri, subpath, cancellable, error); } static JsonNode * @@ -452,7 +433,7 @@ flatpak_oci_registry_ensure_local (FlatpakOciRegistry *self, return FALSE; } - oci_layout_bytes = local_load_file (dfd, "oci-layout", NULL, NULL, cancellable, &local_error); + oci_layout_bytes = local_load_file (dfd, "oci-layout", cancellable, &local_error); if (oci_layout_bytes == NULL) { if (for_write && g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) @@ -546,20 +527,15 @@ flatpak_oci_registry_initable_iface_init (GInitableIface *iface) FlatpakOciIndex * flatpak_oci_registry_load_index (FlatpakOciRegistry *self, - const char *etag, - char **etag_out, GCancellable *cancellable, GError **error) { g_autoptr(GBytes) bytes = NULL; g_autoptr(GError) local_error = NULL; - if (etag_out) - *etag_out = NULL; - g_assert (self->valid); - bytes = flatpak_oci_registry_load_file (self, "index.json", etag, etag_out, cancellable, &local_error); + bytes = flatpak_oci_registry_load_file (self, "index.json", cancellable, &local_error); if (bytes == NULL) { g_propagate_error (error, g_steal_pointer (&local_error)); @@ -910,7 +886,7 @@ flatpak_oci_registry_load_blob (FlatpakOciRegistry *self, if (subpath == NULL) return NULL; - bytes = flatpak_oci_registry_load_file (self, subpath, NULL, NULL, cancellable, error); + bytes = flatpak_oci_registry_load_file (self, subpath, cancellable, error); if (bytes == NULL) return NULL; diff --git a/common/flatpak-utils-http-private.h b/common/flatpak-utils-http-private.h index 84af1d49..c8fa690f 100644 --- a/common/flatpak-utils-http-private.h +++ b/common/flatpak-utils-http-private.h @@ -38,8 +38,6 @@ typedef void (*FlatpakLoadUriProgress) (guint64 downloaded_bytes, GBytes * flatpak_load_http_uri (SoupSession *soup_session, const char *uri, FlatpakHTTPFlags flags, - const char *etag, - char **out_etag, FlatpakLoadUriProgress progress, gpointer user_data, GCancellable *cancellable, diff --git a/common/flatpak-utils-http.c b/common/flatpak-utils-http.c index d89de299..30cba214 100644 --- a/common/flatpak-utils-http.c +++ b/common/flatpak-utils-http.c @@ -52,7 +52,6 @@ typedef struct gpointer user_data; guint64 last_progress_time; CacheHttpData *cache_data; - char *etag; } LoadUriData; #define CACHE_HTTP_XATTR "user.flatpak.http" @@ -451,8 +450,6 @@ load_uri_callback (GObject *source_object, if (data->cache_data) set_cache_http_data_from_headers (data->cache_data, msg); - data->etag = g_strdup (soup_message_headers_get_one (msg->response_headers, "ETag")); - if (data->out_tmpfile) { if (!glnx_open_tmpfile_linkable_at (data->out_tmpfile_parent_dfd, ".", @@ -496,8 +493,6 @@ GBytes * flatpak_load_http_uri (SoupSession *soup_session, const char *uri, FlatpakHTTPFlags flags, - const char *etag, - char **out_etag, FlatpakLoadUriProgress progress, gpointer user_data, GCancellable *cancellable, @@ -530,8 +525,6 @@ flatpak_load_http_uri (SoupSession *soup_session, return NULL; m = soup_request_http_get_message (request); - if (etag) - soup_message_headers_replace (m->request_headers, "If-None-Match", etag); if (flags & FLATPAK_HTTP_FLAGS_ACCEPT_OCI) soup_message_headers_replace (m->request_headers, "Accept", @@ -546,18 +539,12 @@ flatpak_load_http_uri (SoupSession *soup_session, if (data.error) { g_propagate_error (error, data.error); - g_free (data.etag); return NULL; } bytes = g_string_free_to_bytes (g_steal_pointer (&content)); g_debug ("Received %" G_GUINT64_FORMAT " bytes", data.downloaded_bytes); - if (out_etag) - *out_etag = g_steal_pointer (&data.etag); - - g_free (data.etag); - return bytes; } diff --git a/common/flatpak-utils.c b/common/flatpak-utils.c index dc1f3c9a..8c166eb2 100644 --- a/common/flatpak-utils.c +++ b/common/flatpak-utils.c @@ -4889,7 +4889,7 @@ flatpak_mirror_image_from_oci (FlatpakOciRegistry *dst_registry, } - index = flatpak_oci_registry_load_index (dst_registry, NULL, NULL, NULL, NULL); + index = flatpak_oci_registry_load_index (dst_registry, NULL, NULL); if (index == NULL) index = flatpak_oci_index_new (); diff --git a/system-helper/flatpak-system-helper.c b/system-helper/flatpak-system-helper.c index 99265373..c091f7b1 100644 --- a/system-helper/flatpak-system-helper.c +++ b/system-helper/flatpak-system-helper.c @@ -265,7 +265,7 @@ handle_deploy (FlatpakSystemHelper *object, return TRUE; } - index = flatpak_oci_registry_load_index (registry, NULL, NULL, NULL, &error); + index = flatpak_oci_registry_load_index (registry, NULL, &error); if (index == NULL) { g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED,