From 6863dca73aaf33a8960bd9412aa950ec8dfbe6db Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Fri, 2 Sep 2011 08:50:06 +0530 Subject: [PATCH] retain old file's permissions in wrap_print() wrap_print() was written to create a new file and rename the old one to avoid a partially written file being read by other processes. This has only been reported for the 'projects.list' file, but I just did it for all files as a matter of course. list of files currently written via this function: gl-creater, gl-perms, description, git-daemon-export-ok, projects.list However, some people want to do the following: - set REPO_UMASK tight (0077, default) - manually change the perms to something looser (typically g+rX) for specific repos - set core.sharedRepository to 0750 (git is documented to honor that config if available and to override umask) Except that core.sharedRepository does not apply to files written by gitolite and not git itself. So they would open up their description files and the next compile would close them again! This patch prevents this from happening. If the file already exists, it maintains the same permissions after the rename. --- src/gitolite.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gitolite.pm b/src/gitolite.pm index 0acbfc8..6b466d4 100644 --- a/src/gitolite.pm +++ b/src/gitolite.pm @@ -110,7 +110,9 @@ sub wrap_print { my $fh = wrap_open(">", "$file.$$"); print $fh @text; close($fh) or die "$ABRT close $file failed: $! at ", (caller)[1], " line ", (caller)[2], "\n"; + my $oldmode = ( (stat $file)[2] ); rename "$file.$$", $file; + chmod $oldmode, $file if $oldmode; } sub slurp {