mirror of
https://github.com/flatpak/flatpak.git
synced 2026-03-05 15:48:13 -05:00
lib: Support listing related refs
This commit is contained in:
@@ -420,13 +420,13 @@ gboolean flatpak_dir_fetch_ref_cache (FlatpakDir *self,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
GPtrArray * flatpak_dir_find_remote_related (FlatpakDir *dir,
|
||||
const char *ref,
|
||||
const char *remote_name,
|
||||
const char *ref,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
GPtrArray * flatpak_dir_find_local_related (FlatpakDir *self,
|
||||
const char *ref,
|
||||
const char *remote_name,
|
||||
const char *ref,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ flatpakinclude_HEADERS = \
|
||||
lib/flatpak-error.h \
|
||||
lib/flatpak-installed-ref.h \
|
||||
lib/flatpak-remote-ref.h \
|
||||
lib/flatpak-related-ref.h \
|
||||
lib/flatpak-bundle-ref.h \
|
||||
lib/flatpak-installation.h \
|
||||
lib/flatpak-remote.h \
|
||||
@@ -46,8 +47,10 @@ libflatpak_la_SOURCES = \
|
||||
lib/flatpak-installed-ref.c \
|
||||
lib/flatpak-installed-ref-private.h \
|
||||
lib/flatpak-remote-ref.c \
|
||||
lib/flatpak-bundle-ref.c \
|
||||
lib/flatpak-remote-ref-private.h \
|
||||
lib/flatpak-bundle-ref.c \
|
||||
lib/flatpak-related-ref.c \
|
||||
lib/flatpak-related-ref-private.h \
|
||||
lib/flatpak-remote-private.h \
|
||||
lib/flatpak-remote.c \
|
||||
lib/flatpak-error.c \
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "flatpak-utils.h"
|
||||
#include "flatpak-installation.h"
|
||||
#include "flatpak-installed-ref-private.h"
|
||||
#include "flatpak-related-ref-private.h"
|
||||
#include "flatpak-remote-private.h"
|
||||
#include "flatpak-remote-ref-private.h"
|
||||
#include "flatpak-enum-types.h"
|
||||
@@ -1571,3 +1572,117 @@ flatpak_installation_create_monitor (FlatpakInstallation *self,
|
||||
return g_file_monitor_file (path, G_FILE_MONITOR_NONE,
|
||||
cancellable, error);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* flatpak_installation_list_remote_related_refs_sync:
|
||||
* @self: a #FlatpakInstallation
|
||||
* @remote_name: the name of the remote
|
||||
* @ref: the name of the remote
|
||||
* @cancellable: (nullable): a #GCancellable
|
||||
* @error: return location for a #GError
|
||||
*
|
||||
* Lists all the available refs on @remote_name that are related to
|
||||
* @ref, and the subpaths to use. These are things that are
|
||||
* interesting to install, update, or uninstall together with
|
||||
* @ref. For instance, locale data or debug information.
|
||||
*
|
||||
* The returned list contains all available related refs, but not
|
||||
* everyone should always be installed. For example,
|
||||
* flatpak_related_ref_should_download () returns TRUE if the
|
||||
* reference should be installed/updated with the app, and
|
||||
* flatpak_related_ref_should_delete () returns TRUE if it
|
||||
* should be uninstalled with the main ref.
|
||||
*
|
||||
* Returns: (transfer container) (element-type FlatpakRelatedRef): an GPtrArray of
|
||||
* #FlatpakRelatedRef instances
|
||||
*
|
||||
* Since: 0.6.7
|
||||
*/
|
||||
GPtrArray *
|
||||
flatpak_installation_list_remote_related_refs_sync (FlatpakInstallation *self,
|
||||
const char *remote_name,
|
||||
const char *ref,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(FlatpakDir) dir = flatpak_installation_get_dir (self);
|
||||
g_autoptr(GPtrArray) related = NULL;
|
||||
g_autoptr(GPtrArray) refs = g_ptr_array_new_with_free_func (g_object_unref);
|
||||
int i;
|
||||
|
||||
related = flatpak_dir_find_remote_related (dir, ref, remote_name,
|
||||
cancellable, error);
|
||||
if (related == NULL)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < related->len; i++)
|
||||
{
|
||||
FlatpakRelated *rel = g_ptr_array_index (related, i);
|
||||
FlatpakRelatedRef *ref;
|
||||
|
||||
ref = flatpak_related_ref_new (rel->ref, rel->commit,
|
||||
rel->subpaths, rel->download, rel->delete);
|
||||
|
||||
if (ref)
|
||||
g_ptr_array_add (refs, ref);
|
||||
}
|
||||
|
||||
return g_steal_pointer (&refs);
|
||||
}
|
||||
|
||||
/**
|
||||
* flatpak_installation_list_installed_related_refs_sync:
|
||||
* @self: a #FlatpakInstallation
|
||||
* @remote_name: the name of the remote
|
||||
* @ref: the name of the remote
|
||||
* @cancellable: (nullable): a #GCancellable
|
||||
* @error: return location for a #GError
|
||||
*
|
||||
* Lists all the locally installed refs from @remote_name that are
|
||||
* related to @ref. These are things that are interesting to install,
|
||||
* update, or uninstall together with @ref. For instance, locale data
|
||||
* or debug information.
|
||||
*
|
||||
* This function is similar to flatpak_installation_list_remote_related_refs_sync,
|
||||
* but instead of looking at what is available on the remote, it only looks
|
||||
* at the locally installed refs. This is useful for instance when you're
|
||||
* looking for related refs to uninstall, or when you're planning to use
|
||||
* FLATPAK_UPDATE_FLAGS_NO_PULL to install previously pulled refs.
|
||||
*
|
||||
* Returns: (transfer container) (element-type FlatpakRelatedRef): an GPtrArray of
|
||||
* #FlatpakRelatedRef instances
|
||||
*
|
||||
* Since: 0.6.7
|
||||
*/
|
||||
GPtrArray *
|
||||
flatpak_installation_list_installed_related_refs_sync (FlatpakInstallation *self,
|
||||
const char *remote_name,
|
||||
const char *ref,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(FlatpakDir) dir = flatpak_installation_get_dir (self);
|
||||
g_autoptr(GPtrArray) related = NULL;
|
||||
g_autoptr(GPtrArray) refs = g_ptr_array_new_with_free_func (g_object_unref);
|
||||
int i;
|
||||
|
||||
related = flatpak_dir_find_local_related (dir, ref, remote_name,
|
||||
cancellable, error);
|
||||
if (related == NULL)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < related->len; i++)
|
||||
{
|
||||
FlatpakRelated *rel = g_ptr_array_index (related, i);
|
||||
FlatpakRelatedRef *ref;
|
||||
|
||||
ref = flatpak_related_ref_new (rel->ref, rel->commit,
|
||||
rel->subpaths, rel->download, rel->delete);
|
||||
|
||||
if (ref)
|
||||
g_ptr_array_add (refs, ref);
|
||||
}
|
||||
|
||||
return g_steal_pointer (&refs);
|
||||
}
|
||||
|
||||
@@ -251,5 +251,15 @@ FLATPAK_EXTERN gboolean flatpak_installation_update_appstream_sync (Fla
|
||||
gboolean *out_changed,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
FLATPAK_EXTERN GPtrArray * flatpak_installation_list_remote_related_refs_sync (FlatpakInstallation *self,
|
||||
const char *remote_name,
|
||||
const char *ref,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
FLATPAK_EXTERN GPtrArray * flatpak_installation_list_installed_related_refs_sync (FlatpakInstallation *self,
|
||||
const char *remote_name,
|
||||
const char *ref,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
#endif /* __FLATPAK_INSTALLATION_H__ */
|
||||
|
||||
37
lib/flatpak-related-ref-private.h
Normal file
37
lib/flatpak-related-ref-private.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright © 2015 Red Hat, Inc
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors:
|
||||
* Alexander Larsson <alexl@redhat.com>
|
||||
*/
|
||||
|
||||
#if !defined(__FLATPAK_H_INSIDE__) && !defined(FLATPAK_COMPILATION)
|
||||
#error "Only <flatpak.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __FLATPAK_RELATED_REF_PRIVATE_H__
|
||||
#define __FLATPAK_RELATED_REF_PRIVATE_H__
|
||||
|
||||
#include <flatpak-related-ref.h>
|
||||
#include <flatpak-dir.h>
|
||||
|
||||
FlatpakRelatedRef *flatpak_related_ref_new (const char *full_ref,
|
||||
const char *commit,
|
||||
char **subpaths,
|
||||
gboolean download,
|
||||
gboolean delete);
|
||||
|
||||
#endif /* __FLATPAK_RELATED_REF_PRIVATE_H__ */
|
||||
255
lib/flatpak-related-ref.c
Normal file
255
lib/flatpak-related-ref.c
Normal file
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* Copyright © 2015 Red Hat, Inc
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors:
|
||||
* Alexander Larsson <alexl@redhat.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "flatpak-utils.h"
|
||||
#include "flatpak-related-ref.h"
|
||||
#include "flatpak-enum-types.h"
|
||||
|
||||
/**
|
||||
* SECTION:flatpak-related-ref
|
||||
* @Title: FlatpakRelatedRef
|
||||
* @Short_description: Related application reference
|
||||
*
|
||||
* A FlatpakRelatedRef provides information about an ref that is related
|
||||
* to another ref. For instance, the local extension ref of an app.
|
||||
*
|
||||
* Since: 0.6.7
|
||||
*/
|
||||
|
||||
typedef struct _FlatpakRelatedRefPrivate FlatpakRelatedRefPrivate;
|
||||
|
||||
struct _FlatpakRelatedRefPrivate
|
||||
{
|
||||
char **subpaths;
|
||||
gboolean download;
|
||||
gboolean delete;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (FlatpakRelatedRef, flatpak_related_ref, FLATPAK_TYPE_REF)
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
|
||||
PROP_SUBPATHS,
|
||||
PROP_SHOULD_DOWNLOAD,
|
||||
PROP_SHOULD_DELETE,
|
||||
};
|
||||
|
||||
static void
|
||||
flatpak_related_ref_finalize (GObject *object)
|
||||
{
|
||||
FlatpakRelatedRef *self = FLATPAK_RELATED_REF (object);
|
||||
FlatpakRelatedRefPrivate *priv = flatpak_related_ref_get_instance_private (self);
|
||||
|
||||
g_strfreev (priv->subpaths);
|
||||
|
||||
G_OBJECT_CLASS (flatpak_related_ref_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
flatpak_related_ref_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
FlatpakRelatedRef *self = FLATPAK_RELATED_REF (object);
|
||||
FlatpakRelatedRefPrivate *priv = flatpak_related_ref_get_instance_private (self);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_SHOULD_DOWNLOAD:
|
||||
priv->download = g_value_get_boolean (value);
|
||||
break;
|
||||
|
||||
case PROP_SHOULD_DELETE:
|
||||
priv->delete = g_value_get_boolean (value);
|
||||
break;
|
||||
|
||||
case PROP_SUBPATHS:
|
||||
g_clear_pointer (&priv->subpaths, g_strfreev);
|
||||
priv->subpaths = g_strdupv (g_value_get_boxed (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
flatpak_related_ref_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
FlatpakRelatedRef *self = FLATPAK_RELATED_REF (object);
|
||||
FlatpakRelatedRefPrivate *priv = flatpak_related_ref_get_instance_private (self);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_SHOULD_DOWNLOAD:
|
||||
g_value_set_boolean (value, priv->download);
|
||||
break;
|
||||
|
||||
case PROP_SHOULD_DELETE:
|
||||
g_value_set_boolean (value, priv->delete);
|
||||
break;
|
||||
|
||||
case PROP_SUBPATHS:
|
||||
g_value_set_boxed (value, priv->subpaths);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
flatpak_related_ref_class_init (FlatpakRelatedRefClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->get_property = flatpak_related_ref_get_property;
|
||||
object_class->set_property = flatpak_related_ref_set_property;
|
||||
object_class->finalize = flatpak_related_ref_finalize;
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_SHOULD_DOWNLOAD,
|
||||
g_param_spec_boolean ("should-download",
|
||||
"Should download",
|
||||
"Whether to auto-download the ref with the main ref",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_SHOULD_DELETE,
|
||||
g_param_spec_boolean ("should-delete",
|
||||
"Should delete",
|
||||
"Whether to auto-delete the ref with the main ref",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_SUBPATHS,
|
||||
g_param_spec_boxed ("subpaths",
|
||||
"",
|
||||
"",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
static void
|
||||
flatpak_related_ref_init (FlatpakRelatedRef *self)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* flatpak_related_ref_get_download:
|
||||
* @self: a #FlatpakRelatedRef
|
||||
*
|
||||
* Returns whether to auto-download the ref with the main ref.
|
||||
*
|
||||
* Returns: %TRUE if the ref should be downloaded with the main ref.
|
||||
*
|
||||
* Since: 0.6.7
|
||||
*/
|
||||
gboolean
|
||||
flatpak_related_ref_should_download (FlatpakRelatedRef *self)
|
||||
{
|
||||
FlatpakRelatedRefPrivate *priv = flatpak_related_ref_get_instance_private (self);
|
||||
|
||||
return priv->download;
|
||||
}
|
||||
|
||||
/**
|
||||
* flatpak_related_ref_should_delete:
|
||||
* @self: a #FlatpakRelatedRef
|
||||
*
|
||||
* Returns whether to auto-delete the ref with the main ref.
|
||||
*
|
||||
* Returns: %TRUE if the ref should be deleted with the main ref.
|
||||
*
|
||||
* Since: 0.6.7
|
||||
*/
|
||||
gboolean
|
||||
flatpak_related_ref_should_delete (FlatpakRelatedRef *self)
|
||||
{
|
||||
FlatpakRelatedRefPrivate *priv = flatpak_related_ref_get_instance_private (self);
|
||||
|
||||
return priv->delete;
|
||||
}
|
||||
|
||||
/**
|
||||
* flatpak_related_ref_get_subpaths:
|
||||
* @self: a #FlatpakRelatedRef
|
||||
*
|
||||
* Returns the subpaths that should be installed/updated for the ref.
|
||||
* This returns %NULL if all files should be installed.
|
||||
*
|
||||
* Returns: (transfer none): A strv, or %NULL
|
||||
*
|
||||
* Since: 0.6.7
|
||||
*/
|
||||
const char * const *
|
||||
flatpak_related_ref_get_subpaths (FlatpakRelatedRef *self)
|
||||
{
|
||||
FlatpakRelatedRefPrivate *priv = flatpak_related_ref_get_instance_private (self);
|
||||
|
||||
return (const char * const *) priv->subpaths;
|
||||
}
|
||||
|
||||
|
||||
FlatpakRelatedRef *
|
||||
flatpak_related_ref_new (const char *full_ref,
|
||||
const char *commit,
|
||||
char **subpaths,
|
||||
gboolean download,
|
||||
gboolean delete)
|
||||
{
|
||||
FlatpakRefKind kind = FLATPAK_REF_KIND_APP;
|
||||
FlatpakRelatedRef *ref;
|
||||
|
||||
g_auto(GStrv) parts = NULL;
|
||||
|
||||
parts = g_strsplit (full_ref, "/", -1);
|
||||
|
||||
if (strcmp (parts[0], "app") != 0)
|
||||
kind = FLATPAK_REF_KIND_RUNTIME;
|
||||
|
||||
/* Canonicalize the "no subpaths" case */
|
||||
if (subpaths && *subpaths == NULL)
|
||||
subpaths = NULL;
|
||||
|
||||
ref = g_object_new (FLATPAK_TYPE_RELATED_REF,
|
||||
"kind", kind,
|
||||
"name", parts[1],
|
||||
"arch", parts[2],
|
||||
"branch", parts[3],
|
||||
"commit", commit,
|
||||
"subpaths", subpaths,
|
||||
"should-download", download,
|
||||
"should-delete", delete,
|
||||
NULL);
|
||||
|
||||
return ref;
|
||||
}
|
||||
57
lib/flatpak-related-ref.h
Normal file
57
lib/flatpak-related-ref.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright © 2015 Red Hat, Inc
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors:
|
||||
* Alexander Larsson <alexl@redhat.com>
|
||||
*/
|
||||
|
||||
#if !defined(__FLATPAK_H_INSIDE__) && !defined(FLATPAK_COMPILATION)
|
||||
#error "Only <flatpak.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __FLATPAK_RELATED_REF_H__
|
||||
#define __FLATPAK_RELATED_REF_H__
|
||||
|
||||
typedef struct _FlatpakRelatedRef FlatpakRelatedRef;
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <flatpak-ref.h>
|
||||
|
||||
#define FLATPAK_TYPE_RELATED_REF flatpak_related_ref_get_type ()
|
||||
#define FLATPAK_RELATED_REF(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FLATPAK_TYPE_RELATED_REF, FlatpakRelatedRef))
|
||||
#define FLATPAK_IS_RELATED_REF(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), FLATPAK_TYPE_RELATED_REF))
|
||||
|
||||
FLATPAK_EXTERN GType flatpak_related_ref_get_type (void);
|
||||
|
||||
struct _FlatpakRelatedRef
|
||||
{
|
||||
FlatpakRef parent;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FlatpakRefClass parent_class;
|
||||
} FlatpakRelatedRefClass;
|
||||
|
||||
#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FlatpakRelatedRef, g_object_unref)
|
||||
#endif
|
||||
|
||||
FLATPAK_EXTERN const char * const *flatpak_related_ref_get_subpaths (FlatpakRelatedRef *self);
|
||||
FLATPAK_EXTERN gboolean flatpak_related_ref_should_download (FlatpakRelatedRef *self);
|
||||
FLATPAK_EXTERN gboolean flatpak_related_ref_should_delete (FlatpakRelatedRef *self);
|
||||
|
||||
#endif /* __FLATPAK_RELATED_REF_H__ */
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <flatpak-ref.h>
|
||||
#include <flatpak-installed-ref.h>
|
||||
#include <flatpak-remote-ref.h>
|
||||
#include <flatpak-related-ref.h>
|
||||
#include <flatpak-bundle-ref.h>
|
||||
#include <flatpak-remote.h>
|
||||
#include <flatpak-installation.h>
|
||||
|
||||
Reference in New Issue
Block a user