1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 
3 #include <unistd.h>
4 
5 #include "generator-setup.h"
6 #include "macro.h"
7 #include "mkdir-label.h"
8 #include "rm-rf.h"
9 
lookup_paths_mkdir_generator(LookupPaths * p)10 int lookup_paths_mkdir_generator(LookupPaths *p) {
11         int r, q;
12 
13         assert(p);
14 
15         if (!p->generator || !p->generator_early || !p->generator_late)
16                 return -EINVAL;
17 
18         r = mkdir_p_label(p->generator, 0755);
19 
20         q = mkdir_p_label(p->generator_early, 0755);
21         if (q < 0 && r >= 0)
22                 r = q;
23 
24         q = mkdir_p_label(p->generator_late, 0755);
25         if (q < 0 && r >= 0)
26                 r = q;
27 
28         return r;
29 }
30 
lookup_paths_trim_generator(LookupPaths * p)31 void lookup_paths_trim_generator(LookupPaths *p) {
32         assert(p);
33 
34         /* Trim empty dirs */
35 
36         if (p->generator)
37                 (void) rmdir(p->generator);
38         if (p->generator_early)
39                 (void) rmdir(p->generator_early);
40         if (p->generator_late)
41                 (void) rmdir(p->generator_late);
42 }
43 
lookup_paths_flush_generator(LookupPaths * p)44 void lookup_paths_flush_generator(LookupPaths *p) {
45         assert(p);
46 
47         /* Flush the generated unit files in full */
48 
49         if (p->generator)
50                 (void) rm_rf(p->generator, REMOVE_ROOT|REMOVE_PHYSICAL);
51         if (p->generator_early)
52                 (void) rm_rf(p->generator_early, REMOVE_ROOT|REMOVE_PHYSICAL);
53         if (p->generator_late)
54                 (void) rm_rf(p->generator_late, REMOVE_ROOT|REMOVE_PHYSICAL);
55 
56         if (p->temporary_dir)
57                 (void) rm_rf(p->temporary_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
58 }
59