Skip to content

Commit 1d6a972

Browse files
committed
Add support for external dir hasher
Allows providing hash-cmd. Protocol is that cmd will be executed and output will be used to calculate dir checksum. If program fails - it falls back to rebuilding.
1 parent 7d621d6 commit 1d6a972

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

src/builder-source-dir.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct BuilderSourceDir
3636
{
3737
BuilderSource parent;
3838

39+
char **hash_cmd;
3940
char *path;
4041
char **skip;
4142
};
@@ -49,6 +50,7 @@ G_DEFINE_TYPE (BuilderSourceDir, builder_source_dir, BUILDER_TYPE_SOURCE);
4950

5051
enum {
5152
PROP_0,
53+
PROP_HASH_CMD,
5254
PROP_PATH,
5355
PROP_SKIP,
5456
LAST_PROP
@@ -75,6 +77,10 @@ builder_source_dir_get_property (GObject *object,
7577

7678
switch (prop_id)
7779
{
80+
case PROP_HASH_CMD:
81+
g_value_set_boxed (value, self->hash_cmd);
82+
break;
83+
7884
case PROP_PATH:
7985
g_value_set_string (value, self->path);
8086
break;
@@ -99,6 +105,12 @@ builder_source_dir_set_property (GObject *object,
99105

100106
switch (prop_id)
101107
{
108+
case PROP_HASH_CMD:
109+
tmp = self->hash_cmd;
110+
self->hash_cmd = g_strdupv (g_value_get_boxed (value));
111+
g_strfreev (tmp);
112+
break;
113+
102114
case PROP_PATH:
103115
g_free (self->path);
104116
self->path = g_value_dup_string (value);
@@ -266,12 +278,36 @@ builder_source_dir_update (BuilderSource *source,
266278
return TRUE;
267279
}
268280

281+
GError*
282+
builder_source_dir_external_hash_from_cmd(BuilderSourceDir *self,
283+
BuilderCache *cache)
284+
{
285+
GError *error = NULL;
286+
gchar *stdout_output = NULL;
287+
if (!g_spawn_sync(NULL, self->hash_cmd, NULL, G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_SEARCH_PATH, NULL, NULL, &stdout_output, NULL, NULL, &error)) {
288+
return error;
289+
}
290+
builder_cache_checksum_data(cache, stdout_output, strlen(stdout_output) + 1)
291+
g_free (stdout_output);
292+
return NULL;
293+
}
294+
269295
static void
270296
builder_source_dir_checksum (BuilderSource *source,
271297
BuilderCache *cache,
272298
BuilderContext *context)
273299
{
274-
/* We can't realistically checksum a directory, so always rebuild */
300+
BuilderSourceDir *self = BUILDER_SOURCE_DIR (source);
301+
if (self->hash_cmd) {
302+
GError* error = builder_source_dir_external_hash_from_cmd(self, cache);
303+
if (!error)
304+
return;
305+
306+
g_error_free(error);
307+
}
308+
309+
/* Checksumming a directory is a non-trivial pursuit. We currently opt to not integrate into flatpak directly
310+
and rather always rebuild */
275311
builder_cache_checksum_random (cache);
276312
}
277313

@@ -292,6 +328,14 @@ builder_source_dir_class_init (BuilderSourceDirClass *klass)
292328
source_class->update = builder_source_dir_update;
293329
source_class->checksum = builder_source_dir_checksum;
294330

331+
g_object_class_install_property (object_class,
332+
PROP_HASH_CMD,
333+
g_param_spec_boxed ("hash-cmd",
334+
"",
335+
"",
336+
G_TYPE_STRV,
337+
G_PARAM_READWRITE));
338+
295339
g_object_class_install_property (object_class,
296340
PROP_PATH,
297341
g_param_spec_string ("path",

0 commit comments

Comments
 (0)