{"thread":{"id":"4921","subject":"[PATCH] tar-tree: add the \"tar.applyUmask\" config option","startedAt":"2006-07-19T21:40:25Z","lastAt":"2006-07-24T06:42:23Z","messageCount":9,"participants":["Willy Tarreau","Junio C Hamano","Johannes Schindelin","Rene Scharfe","Rogan Dawes"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"23933","messageId":"20060719214025.GA10997@1wt.eu","threadId":"4921","inReplyTo":null,"subject":"[PATCH] tar-tree: add the \"tar.applyUmask\" config option","fromName":"Willy Tarreau","fromEmail":"w@1wt.eu","sentAt":"2006-07-19T21:40:25Z","receivedAt":"2006-07-19T21:40:25Z","isPatch":true,"sender":{"key":"w@1wt.eu","avatar":"https://avatars.githubusercontent.com/u/8141789?v=4"},"body":"Hi Junio, Hi Rene,\n\nWhile I agreed with Linus that the very permissive file modes set in tar\narchives were not particularly a problem for kernel users, I'm finding\nthat for some other projects it sometimes becomes really annoying, to\nthe point that I finally considered using a plain tar instead. This is a\nshame because tar-tree is really fast an powerful, and I like its ability\nto enforce permissions when those of the local dir might be wrong for\nvarious reasons.\n\nSo I added a config option to tell tar-tree to respect the user's umask\nto the files and dirs listed in the output tar file. By default, this\noption is not set, of course, but once set to true, the files look somewhat\nbetter :\n\n$ cat .git/config\n[core]\n        repositoryformatversion = 0\n        filemode = true\n\n[tar]\n        applyUmask = true\n\n$ ./git-tar-tree HEAD | tar tvf -|head\n-rw-r--r-- git/git        1887 2006-07-19 23:23:00 .gitignore\n-rw-r--r-- git/git       18787 2006-07-19 23:23:00 COPYING\ndrwxr-xr-x git/git           0 2006-07-19 23:23:00 Documentation/\n-rw-r--r-- git/git          52 2006-07-19 23:23:00 Documentation/.gitignore\n-rw-r--r-- git/git        2463 2006-07-19 23:23:00 Documentation/Makefile\n-rw-r--r-- git/git       11550 2006-07-19 23:23:00 Documentation/SubmittingPatches\n-rw-r--r-- git/git         822 2006-07-19 23:23:00 Documentation/asciidoc.conf\n-rwxr-xr-x git/git        1049 2006-07-19 23:23:00 Documentation/build-docdep.perl\n-rw-r--r-- git/git         596 2006-07-19 23:23:00 Documentation/callouts.xsl\n\n\nLet me insist on the fact that the default behaviour is unchanged.\nWould you consider this for inclusion ? I've made the patch below\nagainst <master>. Please check on your side that the doc generates\nvalid output, as I've never managed to install the asciidoc/xmlto\ntoolchain.\n\nPlease keep me CCed in replies as I'm not subscribed to the git list.\n\nRegards,\nWilly\n\n--\n\n>From dcc976d83c3b9c85460329932ce22547b7f5f3f9 Mon Sep 17 00:00:00 2001\nFrom: Willy Tarreau <w@1wt.eu>\nDate: Wed, 19 Jul 2006 23:23:00 +0200\nSubject: tar-tree: add the \"tar.applyUmask\" config option\n\nFor some projects, producing tar files with world-writable files\ncan be problematic. This change introduces a the \"tar.applyUmask\"\nconfig option to make tar-tree apply the umask to the permissions\nset in the tar file.\n\nSigned-off-by: Willy Tarreau <w@1wt.eu>\n---\n Documentation/config.txt |    9 +++++++++\n builtin-tar-tree.c       |   19 ++++++++++++++++---\n 2 files changed, 25 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 0b434c1..32519a9 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -208,6 +208,15 @@ showbranch.default::\n \tThe default set of branches for gitlink:git-show-branch[1].\n \tSee gitlink:git-show-branch[1].\n \n+tar.applyUmask::\n+\tBy default, git-link:git-tar-tree[1] sets file and directories modes\n+\tto 0666 or 0777. While this is both useful and acceptable for projects\n+\tsuch as the Linux Kernel, it might be excessive for other projects.\n+\tSetting this variable to true makes git-link:git-tar-tree[1] apply the\n+\tumask to the modes above. This should be enough for most projects, as\n+\tit will lead to the same permissions as git-link:git-checkout[1] would\n+\tuse. The default is false.\n+\n user.email::\n \tYour email address to be recorded in any newly created commits.\n \tCan be overridden by the 'GIT_AUTHOR_EMAIL' and 'GIT_COMMITTER_EMAIL'\ndiff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\nindex f2e48aa..f66f6ad 100644\n--- a/builtin-tar-tree.c\n+++ b/builtin-tar-tree.c\n@@ -20,6 +20,7 @@ static char block[BLOCKSIZE];\n static unsigned long offset;\n \n static time_t archive_time;\n+static int tar_umask;\n \n /* tries hard to write, either succeeds or dies in the attempt */\n static void reliable_write(const void *data, unsigned long size)\n@@ -188,13 +189,13 @@ static void write_entry(const unsigned c\n \t} else {\n \t\tif (S_ISDIR(mode)) {\n \t\t\t*header.typeflag = TYPEFLAG_DIR;\n-\t\t\tmode |= 0777;\n+\t\t\tmode |= 0777 & ~tar_umask;\n \t\t} else if (S_ISLNK(mode)) {\n \t\t\t*header.typeflag = TYPEFLAG_LNK;\n \t\t\tmode |= 0777;\n \t\t} else if (S_ISREG(mode)) {\n \t\t\t*header.typeflag = TYPEFLAG_REG;\n-\t\t\tmode |= (mode & 0100) ? 0777 : 0666;\n+\t\t\tmode |= ((mode & 0100) ? 0777 : 0666) &\t~tar_umask;\n \t\t} else {\n \t\t\terror(\"unsupported file mode: 0%o (SHA1: %s)\",\n \t\t\t      mode, sha1_to_hex(sha1));\n@@ -293,6 +294,18 @@ static void traverse_tree(struct tree_de\n \t}\n }\n \n+int git_tar_config(const char *var, const char *value)\n+{\n+\tif (!strcmp(var, \"tar.applyumask\")) {\n+\t\tif (git_config_bool(var, value)) {\n+\t\t\ttar_umask = umask(0);\n+\t\t\tumask(tar_umask);\n+\t\t}\n+\t\treturn 0;\n+\t}\n+\treturn git_default_config(var, value);\n+}\n+\n static int generate_tar(int argc, const char **argv, char** envp)\n {\n \tunsigned char sha1[20], tree_sha1[20];\n@@ -305,7 +318,7 @@ static int generate_tar(int argc, const \n \tcurrent_path.len = current_path.eof = 0;\n \n \tsetup_git_directory();\n-\tgit_config(git_default_config);\n+\tgit_config(git_tar_config);\n \n \tswitch (argc) {\n \tcase 3:\n-- \n1.4.1\n"},{"id":"23934","messageId":"7vd5c1jkc3.fsf@assigned-by-dhcp.cox.net","threadId":"4921","inReplyTo":"20060719214025.GA10997@1wt.eu","subject":"Re: [PATCH] tar-tree: add the \"tar.applyUmask\" config option","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-07-19T22:33:48Z","receivedAt":"2006-07-19T22:33:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Willy Tarreau <w@1wt.eu> writes:\n\n> While I agreed with Linus that the very permissive file modes set in tar\n> archives were not particularly a problem for kernel users, I'm finding\n> that for some other projects it sometimes becomes really annoying, to\n> the point that I finally considered using a plain tar instead. This is a\n> shame because tar-tree is really fast an powerful, and I like its ability\n> to enforce permissions when those of the local dir might be wrong for\n> various reasons.\n\nI do not have problem with an option to allow a non-default\nbehaviour in this area.  Maybe we might want to be able to set\nthe mask in the configuration file as well, perhaps like...\n\n\ttar.umask = user ;# use from the current process'\n        tar.umask = 0    ;# same as default\n        tar.umask = 002  ;# group friendly\n"},{"id":"23935","messageId":"Pine.LNX.4.63.0607200038580.29667@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"4921","inReplyTo":"20060719214025.GA10997@1wt.eu","subject":"Re: [PATCH] tar-tree: add the \"tar.applyUmask\" config option","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-07-19T22:39:39Z","receivedAt":"2006-07-19T22:39:39Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nwhile at it, you could ask an explicit \"--umask=<n>\" flag, no?\n\nCiao,\nDscho\n"},{"id":"23936","messageId":"20060719225021.GA28591@1wt.eu","threadId":"4921","inReplyTo":"7vd5c1jkc3.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] tar-tree: add the \"tar.applyUmask\" config option","fromName":"Willy Tarreau","fromEmail":"w@1wt.eu","sentAt":"2006-07-19T22:50:21Z","receivedAt":"2006-07-19T22:50:21Z","isPatch":true,"sender":{"key":"w@1wt.eu","avatar":"https://avatars.githubusercontent.com/u/8141789?v=4"},"body":"On Wed, Jul 19, 2006 at 03:33:48PM -0700, Junio C Hamano wrote:\n> Willy Tarreau <w@1wt.eu> writes:\n> \n> > While I agreed with Linus that the very permissive file modes set in tar\n> > archives were not particularly a problem for kernel users, I'm finding\n> > that for some other projects it sometimes becomes really annoying, to\n> > the point that I finally considered using a plain tar instead. This is a\n> > shame because tar-tree is really fast an powerful, and I like its ability\n> > to enforce permissions when those of the local dir might be wrong for\n> > various reasons.\n> \n> I do not have problem with an option to allow a non-default\n> behaviour in this area.  Maybe we might want to be able to set\n> the mask in the configuration file as well, perhaps like...\n> \n> \ttar.umask = user ;# use from the current process'\n>         tar.umask = 0    ;# same as default\n>         tar.umask = 002  ;# group friendly\n\nThis is an excellent idea. I will try to find some spare time tomorrow\nto implement it. I've also seen the proposal about the --umask= option.\nI don't think it's absolutely necessary since the umask has little reason\nto change during the repo's life, but if the implementation is obvious,\nI will do it too.\n\nThanks for your suggestion,\nWilly\n"},{"id":"23946","messageId":"44BF3B4A.5040109@lsrfire.ath.cx","threadId":"4921","inReplyTo":"20060719214025.GA10997@1wt.eu","subject":"Re: [PATCH] tar-tree: add the \"tar.applyUmask\" config option","fromName":"Rene Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2006-07-20T08:14:02Z","receivedAt":"2006-07-20T08:14:02Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Hi Willy,\n\nI kind of like the change, because it gives the user more control.\nTheoretically this would not be needed, because tar can apply the\numask at extract time just fine.  In practice I can't see why we\nshould forbid users from creating the archives just the way they\nlike them, no matter what their reasoning might be.\n\nWilly Tarreau schrieb:\n> +tar.applyUmask::\n> +\tBy default, git-link:git-tar-tree[1] sets file and directories modes\n> +\tto 0666 or 0777. While this is both useful and acceptable for projects\n> +\tsuch as the Linux Kernel, it might be excessive for other projects.\n> +\tSetting this variable to true makes git-link:git-tar-tree[1] apply the\n> +\tumask to the modes above. This should be enough for most projects, as\n> +\tit will lead to the same permissions as git-link:git-checkout[1] would\n> +\tuse. The default is false.\n\nComments about why this change is needed and that it is sufficient\nshould go into the commit message.  For the rest of the patch:\n\nAcked-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n"},{"id":"23949","messageId":"20060720093044.GA10824@1wt.eu","threadId":"4921","inReplyTo":"7vd5c1jkc3.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] tar-tree: add the \"tar.applyUmask\" config option","fromName":"Willy Tarreau","fromEmail":"w@1wt.eu","sentAt":"2006-07-20T09:30:44Z","receivedAt":"2006-07-20T09:30:44Z","isPatch":true,"sender":{"key":"w@1wt.eu","avatar":"https://avatars.githubusercontent.com/u/8141789?v=4"},"body":"Hi Junio,\n\nOn Wed, Jul 19, 2006 at 03:33:48PM -0700, Junio C Hamano wrote:\n> Willy Tarreau <w@1wt.eu> writes:\n> \n> > While I agreed with Linus that the very permissive file modes set in tar\n> > archives were not particularly a problem for kernel users, I'm finding\n> > that for some other projects it sometimes becomes really annoying, to\n> > the point that I finally considered using a plain tar instead. This is a\n> > shame because tar-tree is really fast an powerful, and I like its ability\n> > to enforce permissions when those of the local dir might be wrong for\n> > various reasons.\n> \n> I do not have problem with an option to allow a non-default\n> behaviour in this area.  Maybe we might want to be able to set\n> the mask in the configuration file as well, perhaps like...\n> \n> \ttar.umask = user ;# use from the current process'\n>         tar.umask = 0    ;# same as default\n>         tar.umask = 002  ;# group friendly\n\nHere's the new version following your suggestion above. I really liked it.\nI've also added a configuration example in the doc. Once again, please\nensure that the doc generates correctly.\n\nThanks,\nWilly\n\n\n>From d8a0d2bbd2365b719a7f68edd78c77a0fd903cab Mon Sep 17 00:00:00 2001\nFrom: Willy Tarreau <w@1wt.eu>\nDate: Thu, 20 Jul 2006 11:23:40 +0200\nSubject: tar-tree: add the \"tar.umask\" config option\n\nBy default, git-tar-tree(1) sets file and directories modes to 0666\nor 0777. While this is both useful and acceptable for projects such\nas the Linux Kernel, it might be excessive for other projects. With\nthis variable, it becomes possible to tell git-tar-tree(1) to apply\na specific umask to the modes above. The special value \"user\"\nindicates that the user's current umask will be used. This should be\nenough for most projects, as it will lead to the same permissions as\ngit-checkout(1) would use. The default value remains 0, which means\nworld read-write.\n\nSigned-off-by: Willy Tarreau <w@1wt.eu>\n---\n Documentation/config.txt       |   11 +++++++++++\n Documentation/git-tar-tree.txt |   15 ++++++++++++++-\n builtin-tar-tree.c             |   21 ++++++++++++++++++---\n 3 files changed, 43 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 0b434c1..f4985d4 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -208,6 +208,17 @@ showbranch.default::\n \tThe default set of branches for gitlink:git-show-branch[1].\n \tSee gitlink:git-show-branch[1].\n \n+tar.umask::\n+\tBy default, git-link:git-tar-tree[1] sets file and directories modes\n+\tto 0666 or 0777. While this is both useful and acceptable for projects\n+\tsuch as the Linux Kernel, it might be excessive for other projects.\n+\tWith this variable, it becomes possible to tell\n+\tgit-link:git-tar-tree[1] to apply a specific umask to the modes above.\n+\tThe special value \"user\" indicates that the user's current umask will\n+\tbe used. This should be enough for most projects, as it will lead to\n+\tthe same permissions as git-link:git-checkout[1] would use. The default\n+\tvalue remains 0, which means world read-write.\n+\n user.email::\n \tYour email address to be recorded in any newly created commits.\n \tCan be overridden by the 'GIT_AUTHOR_EMAIL' and 'GIT_COMMITTER_EMAIL'\ndiff --git a/Documentation/git-tar-tree.txt b/Documentation/git-tar-tree.txt\nindex f2675c4..7a99acf 100644\n--- a/Documentation/git-tar-tree.txt\n+++ b/Documentation/git-tar-tree.txt\n@@ -37,7 +37,20 @@ OPTIONS\n \tInstead of making a tar archive from local repository,\n \tretrieve a tar archive from a remote repository.\n \n-Examples\n+CONFIGURATION\n+-------------\n+By default, file and directories modes are set to 0666 or 0777. It is\n+possible to change this by setting the \"umask\" variable in the\n+repository configuration as follows :\n+\n+[tar]\n+        umask = 002\t;# group friendly\n+\n+The special umask value \"user\" indicates that the user's current umask\n+will be used instead. The default value remains 0, which means world\n+readable/writable files and directories.\n+\n+EXAMPLES\n --------\n git tar-tree HEAD junk | (cd /var/tmp/ && tar xf -)::\n \ndiff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\nindex f2e48aa..e5aaded 100644\n--- a/builtin-tar-tree.c\n+++ b/builtin-tar-tree.c\n@@ -20,6 +20,7 @@ static char block[BLOCKSIZE];\n static unsigned long offset;\n \n static time_t archive_time;\n+static int tar_umask;\n \n /* tries hard to write, either succeeds or dies in the attempt */\n static void reliable_write(const void *data, unsigned long size)\n@@ -188,13 +189,13 @@ static void write_entry(const unsigned c\n \t} else {\n \t\tif (S_ISDIR(mode)) {\n \t\t\t*header.typeflag = TYPEFLAG_DIR;\n-\t\t\tmode |= 0777;\n+\t\t\tmode = (mode | 0777) & ~tar_umask;\n \t\t} else if (S_ISLNK(mode)) {\n \t\t\t*header.typeflag = TYPEFLAG_LNK;\n \t\t\tmode |= 0777;\n \t\t} else if (S_ISREG(mode)) {\n \t\t\t*header.typeflag = TYPEFLAG_REG;\n-\t\t\tmode |= (mode & 0100) ? 0777 : 0666;\n+\t\t\tmode = (mode | ((mode & 0100) ? 0777 : 0666)) & ~tar_umask;\n \t\t} else {\n \t\t\terror(\"unsupported file mode: 0%o (SHA1: %s)\",\n \t\t\t      mode, sha1_to_hex(sha1));\n@@ -293,6 +294,20 @@ static void traverse_tree(struct tree_de\n \t}\n }\n \n+int git_tar_config(const char *var, const char *value)\n+{\n+\tif (!strcmp(var, \"tar.umask\")) {\n+\t\tif (!strcmp(value, \"user\")) {\n+\t\t\ttar_umask = umask(0);\n+\t\t\tumask(tar_umask);\n+\t\t} else {\n+\t\t\ttar_umask = git_config_int(var, value);\n+\t\t}\n+\t\treturn 0;\n+\t}\n+\treturn git_default_config(var, value);\n+}\n+\n static int generate_tar(int argc, const char **argv, char** envp)\n {\n \tunsigned char sha1[20], tree_sha1[20];\n@@ -305,7 +320,7 @@ static int generate_tar(int argc, const \n \tcurrent_path.len = current_path.eof = 0;\n \n \tsetup_git_directory();\n-\tgit_config(git_default_config);\n+\tgit_config(git_tar_config);\n \n \tswitch (argc) {\n \tcase 3:\n-- \n1.4.1\n"},{"id":"23950","messageId":"44BF507A.4080801@dawes.za.net","threadId":"4921","inReplyTo":"20060720093044.GA10824@1wt.eu","subject":"Re: [PATCH] tar-tree: add the \"tar.applyUmask\" config option","fromName":"Rogan Dawes","fromEmail":"discard@dawes.za.net","sentAt":"2006-07-20T09:44:26Z","receivedAt":"2006-07-20T09:44:26Z","isPatch":true,"sender":{"key":"discard@dawes.za.net","avatar":null},"body":"Willy Tarreau wrote:\n> +int git_tar_config(const char *var, const char *value)\n> +{\n> +\tif (!strcmp(var, \"tar.umask\")) {\n> +\t\tif (!strcmp(value, \"user\")) {\n> +\t\t\ttar_umask = umask(0);\n> +\t\t\tumask(tar_umask);\n> +\t\t} else {\n> +\t\t\ttar_umask = git_config_int(var, value);\n\nLooks like you forgot:\n    \t\t\tumask(tar_umask);\n\n> +\t\t}\n> +\t\treturn 0;\n> +\t}\n> +\treturn git_default_config(var, value);\n> +}\n\nOr else move it to just before the \"return 0;\" line.\n\nRogan\n"},{"id":"23951","messageId":"20060720095553.GA10920@1wt.eu","threadId":"4921","inReplyTo":"44BF507A.4080801@dawes.za.net","subject":"Re: [PATCH] tar-tree: add the \"tar.applyUmask\" config option","fromName":"Willy Tarreau","fromEmail":"w@1wt.eu","sentAt":"2006-07-20T09:55:53Z","receivedAt":"2006-07-20T09:55:53Z","isPatch":true,"sender":{"key":"w@1wt.eu","avatar":"https://avatars.githubusercontent.com/u/8141789?v=4"},"body":"On Thu, Jul 20, 2006 at 11:44:26AM +0200, Rogan Dawes wrote:\n> Willy Tarreau wrote:\n> >+int git_tar_config(const char *var, const char *value)\n> >+{\n> >+\tif (!strcmp(var, \"tar.umask\")) {\n> >+\t\tif (!strcmp(value, \"user\")) {\n> >+\t\t\ttar_umask = umask(0);\n> >+\t\t\tumask(tar_umask);\n> >+\t\t} else {\n> >+\t\t\ttar_umask = git_config_int(var, value);\n> \n> Looks like you forgot:\n>    \t\t\tumask(tar_umask);\n\nnot at all : we don't want to change the process's umask, but set the\nmask that will be used to position file modes in the output archive.\n\nThe reason for umask(tar_umask) above is because you cannot read the\nprocess umask without changing it, so you have to do it twice with a\ndummy value first.\n\n> >+\t\t}\n> >+\t\treturn 0;\n> >+\t}\n> >+\treturn git_default_config(var, value);\n> >+}\n> \n> Or else move it to just before the \"return 0;\" line.\n> \n> Rogan\n\nRegards,\nWilly\n"},{"id":"24042","messageId":"7vr70bfqr4.fsf@assigned-by-dhcp.cox.net","threadId":"4921","inReplyTo":"44BF3B4A.5040109@lsrfire.ath.cx","subject":"Re: [PATCH] tar-tree: add the \"tar.applyUmask\" config option","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-07-24T06:42:23Z","receivedAt":"2006-07-24T06:42:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"}]}