const char * builder_context_get_arch (BuilderContext *self) { if (self->arch == NULL) self->arch = g_strdup (flatpak_get_arch ()); return (const char *) self->arch; }
static gboolean metadata_get_arch (GFile *file, char **out_arch, GError **error) { g_autofree char *path = NULL; g_autoptr(GKeyFile) keyfile = NULL; g_autofree char *runtime = NULL; g_auto(GStrv) parts = NULL; if (opt_arch != NULL) { *out_arch = g_strdup (opt_arch); return TRUE; } keyfile = g_key_file_new (); path = g_file_get_path (file); if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, error)) return FALSE; runtime = g_key_file_get_string (keyfile, "Application", "runtime", NULL); if (runtime == NULL) runtime = g_key_file_get_string (keyfile, "Application", "sdk", NULL); if (runtime == NULL) runtime = g_key_file_get_string (keyfile, "Runtime", "runtime", NULL); if (runtime == NULL) runtime = g_key_file_get_string (keyfile, "Runtime", "sdk", NULL); if (runtime == NULL) { *out_arch = g_strdup (flatpak_get_arch ()); return TRUE; } parts = g_strsplit (runtime, "/", 0); if (g_strv_length (parts) != 3) return flatpak_fail (error, "Failed to determine arch from metadata runtime key: %s", runtime); *out_arch = g_strdup (parts[1]); return TRUE; }
/** * flatpak_remote_get_appstream_timestamp: * @self: a #FlatpakRemote * @arch: (nullable): which architecture to fetch (default: current architecture) * * Returns the timestamp file that will be updated whenever the appstream information * has been updated (or tried to update) for the specified @arch. * * Returns: (transfer full): a #GFile **/ GFile * flatpak_remote_get_appstream_timestamp (FlatpakRemote *self, const char *arch) { FlatpakRemotePrivate *priv = flatpak_remote_get_instance_private (self); g_autofree char *subdir = NULL; if (priv->dir == NULL) return NULL; if (arch == NULL) arch = flatpak_get_arch (); subdir = g_strdup_printf ("appstream/%s/%s/.timestamp", priv->name, arch); return g_file_resolve_relative_path (flatpak_dir_get_path (priv->dir), subdir); }
gboolean flatpak_builtin_update (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(FlatpakDir) dir = NULL; const char *name = NULL; const char *branch = NULL; gboolean failed = FALSE; int i; context = g_option_context_new ("[NAME [BRANCH]] - Update an application or runtime"); if (!flatpak_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error)) return FALSE; if (argc < 1) return usage_error (context, "NAME must be specified", error); if (argc >= 2) name = argv[1]; if (argc >= 3) branch = argv[2]; if (opt_arch == NULL) opt_arch = (char *)flatpak_get_arch (); if (!opt_app && !opt_runtime) opt_app = opt_runtime = TRUE; if (opt_appstream) return update_appstream (dir, name, cancellable, error); if (opt_app) { g_auto(GStrv) refs = NULL; if (!flatpak_dir_list_refs (dir, "app", &refs, cancellable, error)) return FALSE; for (i = 0; refs != NULL && refs[i] != NULL; i++) { g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], error); if (parts == NULL) return FALSE; if (name != NULL && strcmp (parts[1], name) != 0) continue; if (strcmp (parts[2], opt_arch) != 0) continue; if (branch != NULL && strcmp (parts[3], branch) != 0) continue; g_print ("Updating application %s %s\n", parts[1], parts[3]); if (!do_update (dir, refs[i], cancellable, error)) return FALSE; } } if (opt_runtime) { g_auto(GStrv) refs = NULL; if (!flatpak_dir_list_refs (dir, "runtime", &refs, cancellable, error)) return FALSE; for (i = 0; refs != NULL && refs[i] != NULL; i++) { g_auto(GStrv) parts = flatpak_decompose_ref (refs[i], error); g_autoptr(GError) local_error = NULL; if (parts == NULL) return FALSE; if (name != NULL && strcmp (parts[1], name) != 0) continue; if (strcmp (parts[2], opt_arch) != 0) continue; if (branch != NULL && strcmp (parts[3], branch) != 0) continue; g_print ("Updating runtime %s %s\n", parts[1], parts[3]); if (!do_update (dir, refs[i], cancellable, &local_error)) { g_printerr ("error updating: %s\n", local_error->message); failed = TRUE; } } } flatpak_dir_cleanup_removed (dir, cancellable, NULL); if (failed) return flatpak_fail (error, "One or more updates failed"); return TRUE; }
gboolean flatpak_option_context_parse (GOptionContext *context, const GOptionEntry *main_entries, int *argc, char ***argv, FlatpakBuiltinFlags flags, FlatpakDir **out_dir, GCancellable *cancellable, GError **error) { g_autoptr(FlatpakDir) dir = NULL; if (!(flags & FLATPAK_BUILTIN_FLAG_NO_DIR)) g_option_context_add_main_entries (context, user_entries, NULL); if (main_entries != NULL) g_option_context_add_main_entries (context, main_entries, NULL); g_option_context_add_main_entries (context, global_entries, NULL); if (!g_option_context_parse (context, argc, argv, error)) return FALSE; if (opt_version) { g_print ("%s\n", PACKAGE_STRING); exit (EXIT_SUCCESS); } if (opt_default_arch) { g_print ("%s\n", flatpak_get_arch ()); exit (EXIT_SUCCESS); } if (opt_supported_arches) { const char **arches = flatpak_get_arches (); int i; for (i = 0; arches[i] != NULL; i++) g_print ("%s\n", arches[i]); exit (EXIT_SUCCESS); } if (!(flags & FLATPAK_BUILTIN_FLAG_NO_DIR)) { dir = flatpak_dir_get (opt_user); if (!flatpak_dir_ensure_path (dir, cancellable, error)) return FALSE; if (!(flags & FLATPAK_BUILTIN_FLAG_NO_REPO) && !flatpak_dir_ensure_repo (dir, cancellable, error)) return FALSE; } if (opt_verbose) g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, message_handler, NULL); if (out_dir) *out_dir = g_steal_pointer (&dir); return TRUE; }