1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
|
/* vi:set et sw=2 sts=2 cin cino=t0,f0,(0,{s,>2s,n-s,^-s,e-s:
* 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.1 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-repo-utils-private.h"
#include "flatpak-utils-private.h"
#include "flatpak-bundle-ref.h"
#include "flatpak-enum-types.h"
/**
* SECTION:flatpak-bundle-ref
* @Title: FlatpakBundleRef
* @Short_description: Application bundle reference
*
* A FlatpakBundleRef refers to a single-file bundle containing an
* application or runtime.
*/
typedef struct _FlatpakBundleRefPrivate FlatpakBundleRefPrivate;
struct _FlatpakBundleRefPrivate
{
GFile *file;
char *origin;
char *runtime_repo;
GBytes *metadata;
GBytes *appstream;
GBytes *icon_64;
GBytes *icon_128;
guint64 installed_size;
};
G_DEFINE_TYPE_WITH_PRIVATE (FlatpakBundleRef, flatpak_bundle_ref, FLATPAK_TYPE_REF)
enum {
PROP_0,
PROP_FILE,
};
static void
flatpak_bundle_ref_finalize (GObject *object)
{
FlatpakBundleRef *self = FLATPAK_BUNDLE_REF (object);
FlatpakBundleRefPrivate *priv = flatpak_bundle_ref_get_instance_private (self);
g_clear_object (&priv->file);
g_bytes_unref (priv->metadata);
g_bytes_unref (priv->appstream);
g_bytes_unref (priv->icon_64);
g_bytes_unref (priv->icon_128);
g_free (priv->origin);
g_free (priv->runtime_repo);
G_OBJECT_CLASS (flatpak_bundle_ref_parent_class)->finalize (object);
}
static void
flatpak_bundle_ref_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
FlatpakBundleRef *self = FLATPAK_BUNDLE_REF (object);
FlatpakBundleRefPrivate *priv = flatpak_bundle_ref_get_instance_private (self);
switch (prop_id)
{
case PROP_FILE:
g_set_object (&priv->file, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
flatpak_bundle_ref_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
FlatpakBundleRef *self = FLATPAK_BUNDLE_REF (object);
FlatpakBundleRefPrivate *priv = flatpak_bundle_ref_get_instance_private (self);
switch (prop_id)
{
case PROP_FILE:
g_value_set_object (value, priv->file);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
flatpak_bundle_ref_class_init (FlatpakBundleRefClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = flatpak_bundle_ref_get_property;
object_class->set_property = flatpak_bundle_ref_set_property;
object_class->finalize = flatpak_bundle_ref_finalize;
/**
* FlatpakBundleRef:file:
*
* The bundle file that this ref refers to.
*/
g_object_class_install_property (object_class,
PROP_FILE,
g_param_spec_object ("file",
"",
"",
G_TYPE_FILE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
}
static void
flatpak_bundle_ref_init (FlatpakBundleRef *self)
{
}
/**
* flatpak_bundle_ref_get_file:
* @self: a #FlatpakBundleRef
*
* Get the file this bundle is stored in.
*
* Returns: (transfer full) : an #GFile
*/
GFile *
flatpak_bundle_ref_get_file (FlatpakBundleRef *self)
{
FlatpakBundleRefPrivate *priv = flatpak_bundle_ref_get_instance_private (self);
return g_object_ref (priv->file);
}
/**
* flatpak_bundle_ref_get_metadata:
* @self: a #FlatpakBundleRef
*
* Get the metadata for the app/runtime
*
* Returns: (transfer full) : an #GBytes with the metadata contents, or %NULL
*/
GBytes *
flatpak_bundle_ref_get_metadata (FlatpakBundleRef *self)
{
FlatpakBundleRefPrivate *priv = flatpak_bundle_ref_get_instance_private (self);
if (priv->metadata)
return g_bytes_ref (priv->metadata);
return NULL;
}
/**
* flatpak_bundle_ref_get_appstream:
* @self: a #FlatpakBundleRef
*
* Get the compressed appstream for the app/runtime
*
* Returns: (transfer full) : an #GBytes with the appstream contents, or %NULL
*/
GBytes *
flatpak_bundle_ref_get_appstream (FlatpakBundleRef *self)
{
FlatpakBundleRefPrivate *priv = flatpak_bundle_ref_get_instance_private (self);
if (priv->appstream)
return g_bytes_ref (priv->appstream);
return NULL;
}
/**
* flatpak_bundle_ref_get_icon:
* @self: a #FlatpakBundleRef
* @size: 64 or 128
*
* Get the icon png data for the app/runtime
*
* Returns: (transfer full) : an #GBytes with png contents
*/
GBytes *
flatpak_bundle_ref_get_icon (FlatpakBundleRef *self,
int size)
{
FlatpakBundleRefPrivate *priv = flatpak_bundle_ref_get_instance_private (self);
if (size == 64 && priv->icon_64)
return g_bytes_ref (priv->icon_64);
if (size == 128 && priv->icon_128)
return g_bytes_ref (priv->icon_128);
return NULL;
}
/**
* flatpak_bundle_ref_get_origin:
* @self: a #FlatpakBundleRef
*
* Get the origin url stored in the bundle
*
* Returns: (transfer full) : an url string, or %NULL
*/
char *
flatpak_bundle_ref_get_origin (FlatpakBundleRef *self)
{
FlatpakBundleRefPrivate *priv = flatpak_bundle_ref_get_instance_private (self);
return g_strdup (priv->origin);
}
/**
* flatpak_bundle_ref_get_runtime_repo_url:
* @self: a #FlatpakBundleRef
*
* Get the runtime flatpakrepo url stored in the bundle (if any)
*
* Returns: (transfer full) : an url string, or %NULL
*
* Since: 0.8.0
*/
char *
flatpak_bundle_ref_get_runtime_repo_url (FlatpakBundleRef *self)
{
FlatpakBundleRefPrivate *priv = flatpak_bundle_ref_get_instance_private (self);
return g_strdup (priv->runtime_repo);
}
/**
* flatpak_bundle_ref_get_installed_size:
* @self: a FlatpakBundleRef
*
* Returns the installed size for the bundle.
*
* Returns: the installed size
*/
guint64
flatpak_bundle_ref_get_installed_size (FlatpakBundleRef *self)
{
FlatpakBundleRefPrivate *priv = flatpak_bundle_ref_get_instance_private (self);
return priv->installed_size;
}
/**
* flatpak_bundle_ref_new:
* @file: a #GFile
* @error: (allow-none): return location for an error
*
* Creates a new bundle ref for the given file.
*
* Returns: a new bundle ref.
*/
FlatpakBundleRef *
flatpak_bundle_ref_new (GFile *file,
GError **error)
{
FlatpakRefKind kind;
FlatpakBundleRefPrivate *priv;
FlatpakBundleRef *ref;
g_autoptr(GVariant) metadata = NULL;
g_autofree char *commit = NULL;
g_autofree char *id = NULL;
g_autofree char *arch = NULL;
g_autofree char *branch = NULL;
g_autoptr(FlatpakDecomposed) full_ref = NULL;
g_autofree char *origin = NULL;
g_autofree char *runtime_repo = NULL;
g_autofree char *metadata_contents = NULL;
g_autoptr(GVariant) appstream = NULL;
g_autoptr(GVariant) icon_64 = NULL;
g_autoptr(GVariant) icon_128 = NULL;
guint64 installed_size;
g_autofree char *collection_id = NULL;
metadata = flatpak_bundle_load (file, &commit, &full_ref, &origin, &runtime_repo, &metadata_contents, &installed_size,
NULL, &collection_id, error);
if (metadata == NULL)
return NULL;
kind = flatpak_decomposed_get_kind (full_ref);
id = flatpak_decomposed_dup_id (full_ref);
arch = flatpak_decomposed_dup_arch (full_ref);
branch = flatpak_decomposed_dup_branch (full_ref);
ref = g_object_new (FLATPAK_TYPE_BUNDLE_REF,
"kind", kind,
"name", id,
"arch", arch,
"branch", branch,
"commit", commit,
"file", file,
"collection-id", collection_id,
NULL);
priv = flatpak_bundle_ref_get_instance_private (ref);
if (metadata_contents)
priv->metadata = g_bytes_new_take (metadata_contents,
strlen (metadata_contents));
metadata_contents = NULL; /* Stolen */
appstream = g_variant_lookup_value (metadata, "appdata", G_VARIANT_TYPE_BYTESTRING);
if (appstream)
priv->appstream = g_variant_get_data_as_bytes (appstream);
icon_64 = g_variant_lookup_value (metadata, "icon-64", G_VARIANT_TYPE_BYTESTRING);
if (icon_64)
priv->icon_64 = g_variant_get_data_as_bytes (icon_64);
icon_128 = g_variant_lookup_value (metadata, "icon-128", G_VARIANT_TYPE_BYTESTRING);
if (icon_128)
priv->icon_128 = g_variant_get_data_as_bytes (icon_128);
priv->installed_size = installed_size;
priv->origin = g_steal_pointer (&origin);
priv->runtime_repo = g_steal_pointer (&runtime_repo);
return ref;
}
|