-
Notifications
You must be signed in to change notification settings - Fork 15
/
purge.c
49 lines (38 loc) · 1.27 KB
/
purge.c
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
// Deletes all build data unatomically. Running containers that rely on the
// build data will enter an undefined state. Plashs behaviour while this command
// did not finish running returning an non zero exit code is undefined. The
// data directory itself is not deleted as it could be a mountpoint.
#define USAGE "usage: plash purge [ --yes ]\n"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <plash.h>
int confirm_via_input() {
printf("Delete all build data? [y/N] ");
char inp[sizeof("y\n")];
fgets(inp, sizeof(inp), stdin);
return (strcmp(inp, "y\n") == 0);
}
int is_confirmed_via_argv(char **argv) {
return (argv[1] && (strcmp(argv[1], "--yes") == 0));
}
int purge_main(int argc, char *argv[]) {
if (!(is_confirmed_via_argv(argv) || confirm_via_input())) {
fputs("Action not confirmed\n", stderr);
return EXIT_FAILURE;
}
pl_unshare_user();
char *plash_data = plash("data");
if (chdir(plash_data) == -1)
pl_fatal("chdir %s", plash_data);
// this one first
pl_run("rm", "rm", "-rf", "id_counter");
pl_run("rm", "-rf", "index");
pl_run("rm", "-rf", "layer");
pl_run("rm", "-rf", "map");
pl_run("rm", "-rf", "mnt");
pl_run("rm", "-rf", "tmp");
fputs("All deleted.\n", stderr);
return EXIT_SUCCESS;
}