From 02e2b8f3473f6a66b3629b09f3256b799a53e003 Mon Sep 17 00:00:00 2001 From: James S White Date: Wed, 6 Apr 2011 14:28:08 -0500 Subject: [PATCH 1/2] permissions change on post-receive; added os.stat checks before calls to os.chmod so that the chmod will not be called if the file is already 755. This fixes a problem when the file is owned by root and gitosis gitosis-init run as a non-root user fails with Operation not permitted --- gitosis/init.py | 5 ++++- gitosis/repository.py | 15 ++++++++++----- gitosis/templates/default/hooks/post-receive | 0 3 files changed, 14 insertions(+), 6 deletions(-) mode change 100644 => 100755 gitosis/templates/default/hooks/post-receive diff --git a/gitosis/init.py b/gitosis/init.py index 11075dc..6b0d7ad 100644 --- a/gitosis/init.py +++ b/gitosis/init.py @@ -11,6 +11,7 @@ from cStringIO import StringIO from ConfigParser import RawConfigParser +from stat import ST_MODE from gitosis import repository from gitosis import run_hook from gitosis import ssh @@ -78,7 +79,9 @@ def init_admin_repository( path=git_dir, ) hook = os.path.join(git_dir, 'hooks', 'post-update') - os.chmod(hook, 0755) + mode = os.stat(hook)[ST_MODE] + if not (mode & 0755) == 0755: + os.chmod(hook, 0755) if not repository.has_initial_commit(git_dir): log.info('Making initial commit...') # ConfigParser does not guarantee order, so jump through hoops diff --git a/gitosis/repository.py b/gitosis/repository.py index 6445e12..069e542 100644 --- a/gitosis/repository.py +++ b/gitosis/repository.py @@ -5,6 +5,7 @@ import subprocess import sys +from stat import ST_MODE from pkg_resources import resource_filename from gitosis import util @@ -42,7 +43,7 @@ def init( template = resource_filename('gitosis.templates', 'default') - util.mkdir(path, 0750) + util.mkdir(path, 0755) args = [ _git, '--git-dir=.', @@ -71,9 +72,13 @@ def init( if not os.path.exists(hooks_dir): raise for hook in hooks: - os.chmod( - os.path.join(hooks_dir, hook), - 0755) + mode = os.stat(os.path.join(hooks_dir, hook))[ST_MODE] + print "%o" % (mode & 0755) + print "%s" % os.path.join(hooks_dir, hook) + if not (mode & 0755) == 0755: + os.chmod( + os.path.join(hooks_dir, hook), + 0755) class GitFastImportError(GitError): @@ -234,4 +239,4 @@ def mirror(git_dir, remote): close_fds=True ) if returncode != 0: - raise GitPushMirrorException('exit status %d' % returncode) \ No newline at end of file + raise GitPushMirrorException('exit status %d' % returncode) diff --git a/gitosis/templates/default/hooks/post-receive b/gitosis/templates/default/hooks/post-receive old mode 100644 new mode 100755 From 75861a9f1afa16692efa528ad465650b525fcfed Mon Sep 17 00:00:00 2001 From: James S White Date: Wed, 6 Apr 2011 14:39:05 -0500 Subject: [PATCH 2/2] removed debugging print statements --- gitosis/repository.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/gitosis/repository.py b/gitosis/repository.py index 069e542..bf66324 100644 --- a/gitosis/repository.py +++ b/gitosis/repository.py @@ -73,8 +73,6 @@ def init( raise for hook in hooks: mode = os.stat(os.path.join(hooks_dir, hook))[ST_MODE] - print "%o" % (mode & 0755) - print "%s" % os.path.join(hooks_dir, hook) if not (mode & 0755) == 0755: os.chmod( os.path.join(hooks_dir, hook),