Skip to content

Commit

Permalink
Merge pull request #239 from michaelolbrich/tmppath
Browse files Browse the repository at this point in the history
genimage: improve tmppath handling
  • Loading branch information
michaelolbrich authored Mar 6, 2024
2 parents fd7cb9e + 942c3dd commit 9fc6446
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 9fc6446

Please sign in to comment.