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
|
/*
* Copyright © 2014 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 <locale.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "libgsystem.h"
#include "libglnx/libglnx.h"
#include "flatpak-builtins.h"
#include "flatpak-utils.h"
#include "flatpak-run.h"
static GOptionEntry options[] = {
{ NULL }
};
gboolean
flatpak_builtin_override (int argc, char **argv, GCancellable *cancellable, GError **error)
{
g_autoptr(GOptionContext) context = NULL;
const char *app;
g_autoptr(FlatpakContext) arg_context = NULL;
g_autoptr(FlatpakDir) dir = NULL;
g_autoptr(GKeyFile) metakey = NULL;
g_autoptr(FlatpakContext) overrides = NULL;
g_autoptr(GError) my_error = NULL;
context = g_option_context_new ("APP - Override settings for application");
arg_context = flatpak_context_new ();
g_option_context_add_group (context, flatpak_context_get_options (arg_context));
if (!flatpak_option_context_parse (context, options, &argc, &argv, 0, &dir, cancellable, error))
return FALSE;
if (argc < 2)
{
usage_error (context, "APP must be specified", error);
return FALSE;
}
app = argv[1];
if (!flatpak_is_valid_name (app))
return flatpak_fail (error, "'%s' is not a valid application name", app);
metakey = flatpak_load_override_keyfile (app, flatpak_dir_is_user (dir), &my_error);
if (metakey == NULL)
{
if (!g_error_matches (my_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
{
g_propagate_error (error, g_steal_pointer (&my_error));
return FALSE;
}
metakey = g_key_file_new ();
}
overrides = flatpak_context_new ();
if (!flatpak_context_load_metadata (overrides, metakey, error))
return FALSE;
flatpak_context_merge (overrides, arg_context);
flatpak_context_save_metadata (overrides, metakey);
if (!flatpak_save_override_keyfile (metakey, app, flatpak_dir_is_user (dir), error))
return FALSE;
return TRUE;
}
|