---
roles/git/checks/files/check-perms.py | 41 ++++++++++++++++++++---------------
1 file changed, 24 insertions(+), 17 deletions(-)
diff --git a/roles/git/checks/files/check-perms.py
b/roles/git/checks/files/check-perms.py
index 7e6501f..8fd8516 100755
--- a/roles/git/checks/files/check-perms.py
+++ b/roles/git/checks/files/check-perms.py
@@ -226,19 +226,25 @@ def set_post_receive_hook_version3(gitdir, fix=False):
error('%s: %s is not a directory.' % (gitdir, dest_prefix))
return False
+ # Remove the old hooks
+ hooks = [
+ os.path.join(dest_prefix, 'post-receive-email'),
+ os.path.join(dest_prefix, 'post-receive-fedmsg'),
+ os.path.join(dest_prefix, 'post-receive-alternativearch'),
+ ]
+
+ for hook in hooks:
+ if os.path.exists(hook):
+ if not fix:
+ error('%s should be removed' % hook)
+ else:
+ os.unlink(hook)
+
# Symlink mail notification and fedmsg scripts to post-receive hook
scripts = {
- '/usr/share/git-core/mail-hooks/gnome-post-receive-email':
- os.path.join(dest_prefix, 'post-receive-email'),
- '/usr/share/git-core/post-receive-fedmsg':
- os.path.join(dest_prefix, 'post-receive-fedmsg'),
- '/usr/share/git-core/post-receive-alternativearch':
- os.path.join(dest_prefix, 'post-receive-alternativearch'),
-
# This one kicks off all the others.
'/usr/share/git-core/post-receive-chained':
os.path.join(gitdir, 'hooks', 'post-receive'),
-
}
for script, hook in scripts.items():
@@ -250,19 +256,20 @@ def set_post_receive_hook_version3(gitdir, fix=False):
error('%s: Hook (%s) not installed.' % (gitdir, hook))
return False
- if os.path.exists(hook):
+ if not os.path.islink(hook):
+ if os.path.exists(hook):
+ try:
+ os.remove(hook)
+ except Exception, e:
+ errstr = hasattr(e, 'strerror') and e.strerror or e
+ error('%s: Error removing %s: %s' % (gitdir, hook, errstr))
+ return False
try:
- os.remove(hook)
+ os.symlink(script, hook)
except Exception, e:
errstr = hasattr(e, 'strerror') and e.strerror or e
- error('%s: Error removing %s: %s' % (gitdir, hook, errstr))
+ error('%s: Error creating %s symlink: %s' % (gitdir, hook,
errstr))
return False
- try:
- os.symlink(script, hook)
- except Exception, e:
- errstr = hasattr(e, 'strerror') and e.strerror or e
- error('%s: Error creating %s symlink: %s' % (gitdir, hook, errstr))
- return False
# We ran the gauntlet.
return True
--
2.9.5
_______________________________________________
infrastructure mailing list -- [email protected]
To unsubscribe send an email to [email protected]