File: artifacts.h

package info (click to toggle)
rauc 1.15-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,336 kB
  • sloc: ansic: 36,989; python: 3,354; sh: 1,391; xml: 53; makefile: 41
file content (240 lines) | stat: -rw-r--r-- 7,076 bytes parent folder | download | duplicates (2)
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
#pragma once

#include <glib.h>

#include "checksum.h"
#include "manifest.h"

#define R_ARTIFACTS_ERROR r_artifacts_error_quark()
GQuark r_artifacts_error_quark(void);

#define R_ARTIFACTS_ERROR_DUPLICATE 0
#define R_ARTIFACTS_ERROR_INSTALL 1

typedef struct _RArtifactRepo RArtifactRepo;

typedef struct _RArtifact {
	/** name of the artifact. A glib intern string. */
	const gchar *name;

	/** details of the source bundle */
	gchar *bundle_compatible;
	gchar *bundle_version;
	gchar *bundle_description;
	gchar *bundle_build;
	gchar *bundle_hash;

	/** original contents of the artifact */
	RaucChecksum checksum;

	/** referenced by parents (intern strings), "" for activated without parent */
	GPtrArray *references;

	/** internally managed pointer to containing repo */
	RArtifactRepo *repo;

	/** internally managed path to the artifact */
	gchar *path;
	/** internally managed temporary path during installation */
	gchar *path_tmp;
} RArtifact;

typedef struct _RArtifactRepo {
	/** name of the repo. (intern string) */
	const gchar *name;
	/** user-friendly description */
	gchar *description;
	/** path this repo uses */
	gchar *path;
	/** type of the repo */
	gchar *type;
	/** associated parent class for redundant repos, may be NULL (intern string) */
	const gchar *parent_class;

	/** the name of the per-repo data subdirectory */
	gchar *data_directory;

	/** nested hash table for artifacts, using interned strings as keys **/
	GHashTable *artifacts;

	/** possible parents (intern strings), "" without parent */
	GPtrArray *possible_references;

	/** runtime information for different repo types */
	union {
		struct {
			GHashTable *local_store_objects;
		} composefs;
	};
} RArtifactRepo;

/**
 * Frees the memory allocated by a RArtifactRepo
 */
void r_artifact_free(gpointer value);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(RArtifact, r_artifact_free);

/**
 * Frees the memory allocated by a RArtifactRepo
 */
void r_artifact_repo_free(gpointer value);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(RArtifactRepo, r_artifact_repo_free);

/**
 * Check if artifact repo type name is valid.
 *
 * @param type Name of type as string
 *
 * @return TRUE if it is a valid (known) slot type, otherwise FALSE
 */
gboolean r_artifact_repo_is_valid_type(const gchar *type)
G_GNUC_WARN_UNUSED_RESULT;

/**
 * Insert an existing RArtifact structure into the repository.
 *
 * The path property of the new to be inserted artifact must be NULL, as this is
 * filled out by this function. During r_artifact_repo_prepare, it is used with
 * artifacts on disk. During installation, the actual copying only happens after
 * inserting it into the repository.
 *
 * @param repo RArtifactRepo to insert into
 * @param artifact RArtifact to insert
 * @param[out] error Return location for a GError, or NULL
 *
 * @return TRUE if the insertion was successful, otherwise FALSE
 */
gboolean r_artifact_repo_insert(RArtifactRepo *repo, RArtifact *artifact, GError **error)
G_GNUC_WARN_UNUSED_RESULT;

/**
 * Scan the repo on disk for installed artifacts and load their information.
 *
 * @param repo RArtifactRepo to prepare
 * @param[out] error Return location for a GError, or NULL
 *
 * @return TRUE if the preparation was successful, otherwise FALSE
 */
gboolean r_artifact_repo_prepare(RArtifactRepo *repo, GError **error)
G_GNUC_WARN_UNUSED_RESULT;

/**
 * Remove unreferenced artifacts and inconsistent data such as partial
 * downloads.
 *
 * @param repo RArtifactRepo to prune
 * @param[out] error Return location for a GError, or NULL
 *
 * @return TRUE if the pruning was successful, otherwise FALSE
 */
gboolean r_artifact_repo_prune(RArtifactRepo *repo, GError **error)
G_GNUC_WARN_UNUSED_RESULT;

/**
 * Update the persistent state from the current configuration in memory.
 *
 * This will create and remove links to artifacts as needed.
 *
 * @param repo RArtifactRepo to commit
 * @param[out] error Return location for a GError, or NULL
 *
 * @return TRUE if the commit was successful, otherwise FALSE
 */
gboolean r_artifact_repo_commit(RArtifactRepo *repo, GError **error)
G_GNUC_WARN_UNUSED_RESULT;

/**
 * Initialize artifact functionality by calling r_artifact_repo_prepare for all
 * configured repositories.
 *
 * @param[out] error Return location for a GError, or NULL
 *
 * @return TRUE if the initialization was successful, otherwise FALSE
 */
gboolean r_artifacts_init(GError **error)
G_GNUC_WARN_UNUSED_RESULT;

/**
 * Call r_artifact_repo_prune for all configured repositories.
 *
 * @param[out] error Return location for a GError, or NULL
 *
 * @return TRUE if the pruning was successful, otherwise FALSE
 */
gboolean r_artifacts_prune(GError **error)
G_GNUC_WARN_UNUSED_RESULT;

/**
 * Converts information on all artifact repos to a GVariant dict.
 *
 * This can be used by the D-Bus service and also for the 'rauc status' CLI
 * command (by converting it to JSON).
 *
 * @return new GVariant containing the dict
 */
GVariant *r_artifacts_to_dict(void)
G_GNUC_WARN_UNUSED_RESULT;

/**
 * Install a tree artifact from the bundle into the repo.
 *
 * @param artifact RArtifact to install to
 * @param image RaucImage to install from
 * @param name the converted directory name in the bundle
 * @param error a GError, or NULL
 *
 * @return TRUE if the installation was successful, otherwise FALSE
 */
gboolean r_tree_artifact_install_extracted(const RArtifact *artifact, const RaucImage *image, const gchar *name, GError **error)
G_GNUC_WARN_UNUSED_RESULT;

/**
 * Try to find an existing artifact given a name and checksum.
 *
 * @param repo RArtifactRepo to search
 * @param name the name to search for
 * @param digest the hash to search for
 *
 * @return the artifact if found, otherwise NULL
 */
RArtifact *r_artifact_find(const RArtifactRepo *repo, const gchar *name, const gchar *digest)
G_GNUC_WARN_UNUSED_RESULT;

/**
 * Install from an image to the intended artifact location.
 *
 * The actual mechanism for the installation depends on the repo type.
 *
 * @param artifact RArtifact to install to
 * @param image RaucImage to install from
 * @param[out] error Return location for a GError, or NULL
 *
 * @return TRUE if the installation was successful, otherwise FALSE
 */
gboolean r_artifact_install(const RArtifact *artifact, const RaucImage *image, GError **error)
G_GNUC_WARN_UNUSED_RESULT;

/**
 * Activate an artifact for the given parent.
 *
 * Other versions of this artifact are deactivated. This change must be
 * separately persisted by r_artifact_repo_commit().
 *
 * @param artifact RArtifact to activate
 * @param parent "" or name of the parent slot
 * @param[out] error Return location for a GError, or NULL
 */
void r_artifact_activate(const RArtifact *artifact, const gchar *parent);

/**
 * Deactivate an artifact for the given parent.
 *
 * This change must be separately persisted by r_artifact_repo_commit().
 *
 * @param artifact RArtifact to deactivate
 * @param parent NULL or name of the parent slot
 * @param[out] error Return location for a GError, or NULL
 */
void r_artifact_deactivate(const RArtifact *artifact, const gchar *parent);