Skip to content

Commit

Permalink
src/bundle: use fakeroot optionally
Browse files Browse the repository at this point in the history
  • Loading branch information
ejoerns committed Jan 20, 2025
1 parent 8c81667 commit eb82553
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions src/bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,10 @@ static gboolean unsquashfs(gint fd, const gchar *contentdir, const gchar *extrac

static gboolean casync_make_blob(const gchar *idxpath, const gchar *contentpath, const gchar *store, GError **error);

static gboolean casync_make_arch(const gchar *idxpath, const gchar *contentpath, const gchar *store, GError **error)
static gboolean casync_make_arch(const gchar *idxpath, const gchar *contentpath, const gchar *store, const gchar *fakeroot, GError **error)
{
GError *ierror = NULL;
gboolean res = FALSE;
g_autoptr(GPtrArray) args = g_ptr_array_new_full(5, g_free);
g_autoptr(GPtrArray) iargs = g_ptr_array_new_full(15, g_free);
g_autofree gchar *tmpdir = NULL;

Expand All @@ -229,14 +228,28 @@ static gboolean casync_make_arch(const gchar *idxpath, const gchar *contentpath,
goto out;
}

r_fakeroot_add_args(iargs, fakeroot);

/* Inner process call (argument of fakroot sh -c) */
g_ptr_array_add(iargs, g_strdup("tar"));
g_ptr_array_add(iargs, g_strdup("xf"));
g_ptr_array_add(iargs, g_strdup(contentpath));
g_ptr_array_add(iargs, g_strdup("-C"));
g_ptr_array_add(iargs, g_strdup(tmpdir));
g_ptr_array_add(iargs, g_strdup("--numeric-owner"));
g_ptr_array_add(iargs, g_strdup("&&"));
g_ptr_array_add(iargs, NULL);

if (!r_subprocess_runv(iargs, G_SUBPROCESS_FLAGS_NONE, &ierror)) {
g_propagate_prefixed_error(error, ierror, "failed to run tar extract: ");
goto out;
}

g_ptr_array_free(iargs, TRUE);

iargs = g_ptr_array_new_full(15, g_free);

r_fakeroot_add_args(iargs, fakeroot);

g_ptr_array_add(iargs, g_strdup("casync"));
g_ptr_array_add(iargs, g_strdup("make"));
g_ptr_array_add(iargs, g_strdup("--with=unix"));
Expand All @@ -261,14 +274,7 @@ static gboolean casync_make_arch(const gchar *idxpath, const gchar *contentpath,
}
g_ptr_array_add(iargs, NULL);

/* Outer process calll */
g_ptr_array_add(args, g_strdup("fakeroot"));
g_ptr_array_add(args, g_strdup("sh"));
g_ptr_array_add(args, g_strdup("-c"));
g_ptr_array_add(args, g_strjoinv(" ", (gchar**) iargs->pdata));
g_ptr_array_add(args, NULL);

res = r_subprocess_runv(args, G_SUBPROCESS_FLAGS_STDOUT_SILENCE, &ierror);
res = r_subprocess_runv(iargs, G_SUBPROCESS_FLAGS_STDOUT_SILENCE, &ierror);
if (!res) {
g_propagate_prefixed_error(
error,
Expand Down Expand Up @@ -1396,7 +1402,7 @@ gboolean resign_bundle(RaucBundle *bundle, const gchar *outpath, GError **error)
return res;
}

static gboolean convert_to_casync_bundle(RaucBundle *bundle, const gchar *outbundle, const gchar **ignore_images, GError **error)
static gboolean convert_to_casync_bundle(RaucBundle *bundle, const gchar *outbundle, const gchar **ignore_images, const gchar *fakeroot, GError **error)
{
GError *ierror = NULL;
gboolean res = FALSE;
Expand Down Expand Up @@ -1475,7 +1481,7 @@ static gboolean convert_to_casync_bundle(RaucBundle *bundle, const gchar *outbun

g_message("Converting %s to casync directory tree idx %s", image->filename, idxfile);

res = casync_make_arch(idxpath, imgpath, storepath, &ierror);
res = casync_make_arch(idxpath, imgpath, storepath, fakeroot, &ierror);
if (!res) {
g_propagate_error(error, ierror);
goto out;
Expand Down Expand Up @@ -1539,6 +1545,7 @@ gboolean create_casync_bundle(RaucBundle *bundle, const gchar *outbundle, const
{
GError *ierror = NULL;
gboolean res = FALSE;
g_autofree GError *cleanup_error = NULL;

g_return_val_if_fail(bundle != NULL, FALSE);
g_return_val_if_fail(outbundle != NULL, FALSE);
Expand All @@ -1549,20 +1556,34 @@ gboolean create_casync_bundle(RaucBundle *bundle, const gchar *outbundle, const
return FALSE;
}

g_autofree gchar *fakeroot = NULL;

if (check_pseudo_active() == FALSE) {
fakeroot = r_fakeroot_init(&ierror);
if (!fakeroot) {
g_propagate_error(error, ierror);
goto out;
}
}

res = check_bundle_payload(bundle, &ierror);
if (!res) {
g_propagate_error(error, ierror);
goto out;
}

res = convert_to_casync_bundle(bundle, outbundle, ignore_images, &ierror);
res = convert_to_casync_bundle(bundle, outbundle, ignore_images, fakeroot, &ierror);
if (!res) {
g_propagate_error(error, ierror);
goto out;
}

res = TRUE;
out:
if (!r_fakeroot_cleanup(fakeroot, &cleanup_error)) {
g_warning("failed to clean up fakeroot environment: %s", cleanup_error->message);
}

/* Remove output file on error */
if (!res &&
g_file_test(outbundle, G_FILE_TEST_IS_REGULAR))
Expand Down

0 comments on commit eb82553

Please sign in to comment.