fix: add "fattr" pledge for chmod(2) for cachefile
improve checks for when head is NULL (empty repo)
1 files changed, 5 insertions(+), 7 deletions(-) | |||
---|---|---|---|
M | stagit.c | +5 | -7 |
1@@ -1003,7 +1003,7 @@ main(int argc, char *argv[])
2 size_t n;
3 int i, fd;
4
5- if (pledge("stdio rpath wpath cpath", NULL) == -1)
6+ if (pledge("stdio rpath wpath cpath fattr", NULL) == -1)
7 err(1, "pledge");
8
9 for (i = 1; i < argc; i++) {
10@@ -1017,6 +1017,8 @@ main(int argc, char *argv[])
11 cachefile = argv[++i];
12 }
13 }
14+ if (!cachefile && pledge("stdio rpath wpath cpath", NULL) == -1)
15+ err(1, "pledge");
16 if (!repodir)
17 usage(argv[0]);
18
19@@ -1037,10 +1039,6 @@ main(int argc, char *argv[])
20 head = git_object_id(obj);
21 git_object_free(obj);
22
23- /* don't cache if there is no HEAD */
24- if (!head)
25- cachefile = NULL;
26-
27 /* use directory name as name */
28 if ((name = strrchr(repodirabs, '/')))
29 name++;
30@@ -1104,7 +1102,7 @@ main(int argc, char *argv[])
31 "<td class=\"num\" align=\"right\"><b>+</b></td>"
32 "<td class=\"num\" align=\"right\"><b>-</b></td></tr>\n</thead><tbody>\n", fp);
33
34- if (cachefile) {
35+ if (cachefile && head) {
36 /* read from cache file (does not need to exist) */
37 if ((rcachefp = fopen(cachefile, "r"))) {
38 if (!fgets(lastoidstr, sizeof(lastoidstr), rcachefp))
39@@ -1167,7 +1165,7 @@ main(int argc, char *argv[])
40 fclose(fp);
41
42 /* rename new cache file on success */
43- if (cachefile) {
44+ if (cachefile && head) {
45 if (rename(tmppath, cachefile))
46 err(1, "rename: '%s' to '%s'", tmppath, cachefile);
47 umask((mask = umask(0)));