URI: 
       fix file permissions for cachefile and respect umask(2) - stagit-gopher - A git gopher frontend. (mirror)
  HTML git clone git://bitreich.org/stagit-gopher/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/stagit-gopher/
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
   DIR commit 769babb131e20c4d7ebe197cfc182bc76ea96c18
   DIR parent 9420a097388c8c90a4f534d3b5f8d4f6b7f195bd
  HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Fri, 17 Nov 2017 16:12:12 +0100
       
       fix file permissions for cachefile and respect umask(2)
       
       Diffstat:
         M stagit-gopher.c                     |      12 ++++++++++--
       
       1 file changed, 10 insertions(+), 2 deletions(-)
       ---
   DIR diff --git a/stagit-gopher.c b/stagit-gopher.c
       @@ -1,4 +1,5 @@
        #include <sys/stat.h>
       +#include <sys/types.h>
        
        #include <err.h>
        #include <errno.h>
       @@ -1083,6 +1084,7 @@ main(int argc, char *argv[])
                git_object *obj = NULL;
                const git_oid *head = NULL;
                const git_error *e = NULL;
       +        mode_t mask;
                FILE *fp, *fpread;
                char path[PATH_MAX], repodirabs[PATH_MAX + 1], *p;
                char tmppath[64] = "cache.XXXXXXXXXXXX", buf[BUFSIZ];
       @@ -1256,8 +1258,14 @@ main(int argc, char *argv[])
                fclose(fp);
        
                /* rename new cache file on success */
       -        if (cachefile && rename(tmppath, cachefile))
       -                err(1, "rename: '%s' to '%s'", tmppath, cachefile);
       +        if (cachefile) {
       +                if (rename(tmppath, cachefile))
       +                        err(1, "rename: '%s' to '%s'", tmppath, cachefile);
       +                umask((mask = umask(0)));
       +                if (chmod(cachefile,
       +                    (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) & ~mask))
       +                        err(1, "chmod: '%s'", cachefile);
       +        }
        
                /* cleanup */
                git_repository_free(repo);