Changeset - 6a90b1ebea2c
[Not reviewed]
default
0 1 0
Mads Kiilerich (mads) - 5 years ago 2020-11-04 13:19:18
mads@kiilerich.com
Grafted from: 501bdf382118
git: write Git hook files atomically

Make sure we don't follow symlinks or inherit permissions from previously
installed hook.
1 file changed with 7 insertions and 4 deletions:
0 comments (0 inline, 0 general)
kallithea/model/scm.py
Show inline comments
 
@@ -27,12 +27,13 @@ Original author and date, and relevant c
 

	
 
import logging
 
import os
 
import posixpath
 
import re
 
import sys
 
import tempfile
 
import traceback
 

	
 
import pkg_resources
 
from tg.i18n import ugettext as _
 

	
 
import kallithea
 
@@ -699,16 +700,18 @@ class ScmModel(object):
 

	
 
            if other_hook and not force:
 
                log.warning('skipping overwriting hook file %s', hook_file)
 
            else:
 
                log.debug('writing %s hook file !', h_type)
 
                try:
 
                    with open(hook_file, 'wb') as f:
 
                        f.write(tmpl.replace(b'_TMPL_', safe_bytes(kallithea.__version__)))
 
                    os.chmod(hook_file, 0o755)
 
                except IOError as e:
 
                    fh, fn = tempfile.mkstemp(prefix=hook_file + '.tmp.')
 
                    os.write(fh, tmpl.replace(b'_TMPL_', safe_bytes(kallithea.__version__)))
 
                    os.close(fh)
 
                    os.chmod(fn, 0o755)
 
                    os.rename(fn, hook_file)
 
                except (OSError, IOError) as e:
 
                    log.error('error writing hook %s: %s', hook_file, e)
 

	
 

	
 
def AvailableRepoGroupChoices(repo_group_perm_level, extras=()):
 
    """Return group_id,string tuples with choices for all the repo groups where
 
    the user has the necessary permissions.
0 comments (0 inline, 0 general)