aboutsummaryrefslogtreecommitdiffstats
path: root/stagit.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <[email protected]>2017-11-19 14:52:04 +0100
committerHiltjo Posthuma <[email protected]>2017-11-19 14:52:04 +0100
commit2ff0c0d6c02dc0d7b5570d12895f12e0ccafd657 (patch)
tree46c7bf2ea6ef6af41ce26e7375bd828990aa9c6a /stagit.c
parent6662b8ee42f0f31c163786d8ed4db2fbf32fdbca (diff)
downloadstagit-2ff0c0d6c02dc0d7b5570d12895f12e0ccafd657.tar.gz
stagit-2ff0c0d6c02dc0d7b5570d12895f12e0ccafd657.zip
fix: add "fattr" pledge for chmod(2) for cachefile
improve checks for when head is NULL (empty repo)
Diffstat (limited to 'stagit.c')
-rw-r--r--stagit.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/stagit.c b/stagit.c
index bf027f6..1bc57e2 100644
--- a/stagit.c
+++ b/stagit.c
@@ -1003,7 +1003,7 @@ main(int argc, char *argv[])
size_t n;
int i, fd;
- if (pledge("stdio rpath wpath cpath", NULL) == -1)
+ if (pledge("stdio rpath wpath cpath fattr", NULL) == -1)
err(1, "pledge");
for (i = 1; i < argc; i++) {
@@ -1017,6 +1017,8 @@ main(int argc, char *argv[])
cachefile = argv[++i];
}
}
+ if (!cachefile && pledge("stdio rpath wpath cpath", NULL) == -1)
+ err(1, "pledge");
if (!repodir)
usage(argv[0]);
@@ -1037,10 +1039,6 @@ main(int argc, char *argv[])
head = git_object_id(obj);
git_object_free(obj);
- /* don't cache if there is no HEAD */
- if (!head)
- cachefile = NULL;
-
/* use directory name as name */
if ((name = strrchr(repodirabs, '/')))
name++;
@@ -1104,7 +1102,7 @@ main(int argc, char *argv[])
"<td class=\"num\" align=\"right\"><b>+</b></td>"
"<td class=\"num\" align=\"right\"><b>-</b></td></tr>\n</thead><tbody>\n", fp);
- if (cachefile) {
+ if (cachefile && head) {
/* read from cache file (does not need to exist) */
if ((rcachefp = fopen(cachefile, "r"))) {
if (!fgets(lastoidstr, sizeof(lastoidstr), rcachefp))
@@ -1167,7 +1165,7 @@ main(int argc, char *argv[])
fclose(fp);
/* rename new cache file on success */
- if (cachefile) {
+ if (cachefile && head) {
if (rename(tmppath, cachefile))
err(1, "rename: '%s' to '%s'", tmppath, cachefile);
umask((mask = umask(0)));