stagit

git site generator
Contents

fix file permissions for cachefile and respect umask(2)

Hiltjo Posthuma hiltjo@codemadness.org

commit: 741eb97 parent: a04bb67
1 files changed, 10 insertions(+), 2 deletions(-)
Mstagit.c+10-2
M · stagit.c +10, -2
 1@@ -1,4 +1,5 @@
 2 #include <sys/stat.h>
 3+#include <sys/types.h>
 4
 5 #include
<err.h>
 6 #include
<errno.h>
 7@@ -995,6 +996,7 @@ main(int argc, char *argv[])
 8 git_object *obj = NULL;
 9 const git_oid
*head = NULL;
10 const git_error
*e = NULL;
11+ mode_t mask;
12 FILE *fp, *fpread;
13 char
path[PATH_MAX], repodirabs[PATH_MAX + 1], *p;
14 char tmppath[64]
= "cache.XXXXXXXXXXXX", buf[BUFSIZ];
15@@ -1165,8 +1167,14 @@ main(int argc, char *argv[])
16 fclose(fp);
17
18 /* rename new
cache file on success */
19- if (cachefile && rename(tmppath, cachefile))
20- err(1,
"rename: '%s' to '%s'", tmppath, cachefile);
21+ if (cachefile) {
22+ if (rename(tmppath,
cachefile))
23+ err(1,
"rename: '%s' to '%s'", tmppath, cachefile);
24+ umask((mask =
umask(0)));
25+ if (chmod(cachefile,
26+
(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) & ~mask))
27+ err(1,
"chmod: '%s'", cachefile);
28+ }
29
30 /* cleanup */
31
git_repository_free(repo);