Skip to content

Commit

Permalink
genimage: improve tmppath handling
Browse files Browse the repository at this point in the history
Right now cleanup is partially broken:
If the tmppath exists, then its content is removed at the end as
expected. However, if the tmppath is missing then it is created but
nothing is removed.

Change this to remove the directory including its content at the end
when the directory was created but stick to removing just the content if
the directory existed before genimage was called.

Fixes: pengutronix#237

Signed-off-by: Michael Olbrich <[email protected]>
  • Loading branch information
michaelolbrich committed Feb 23, 2024
1 parent fd7cb9e commit 942c3dd
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions genimage.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,11 @@ const char *mountpath(const struct image *image)
return mp->mountpath;
}

static int tmppath_generated;
static enum {
TMPPATH_NONE,
TMPPATH_CHECKED,
TMPPATH_CREATED
} tmppath_generated;

static void check_tmp_path(void)
{
Expand All @@ -595,6 +599,7 @@ static void check_tmp_path(void)
ret = systemp(NULL, "mkdir -p \"%s\"", tmppath());
if (ret)
exit(1);
tmppath_generated = TMPPATH_CREATED;
return;
}

Expand All @@ -607,14 +612,22 @@ static void check_tmp_path(void)
exit(1);
}
}
tmppath_generated = 1;
tmppath_generated = TMPPATH_CHECKED;
closedir(dir);
}

static void cleanup(void)
{
if (tmppath_generated)
systemp(NULL, "rm -rf \"%s\"/*", tmppath());
switch (tmppath_generated) {
case TMPPATH_CREATED:
systemp(NULL, "rm -rf \"%s/\"", tmppath());
break;
case TMPPATH_CHECKED:
systemp(NULL, "rm -rf \"%s\"/*", tmppath());
break;
default:
break;
}
}

static cfg_opt_t top_opts[] = {
Expand Down

0 comments on commit 942c3dd

Please sign in to comment.