Changeset - 64c194492aad
[Not reviewed]
beta
0 3 0
Marcin Kuzminski - 13 years ago 2013-02-25 17:16:45
marcin@python-works.com
--version command should be safe, and bare no modifications
- improved subprocess calls error detection
- fixed I/O read on closed file errors
3 files changed with 28 insertions and 7 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/subprocessio.py
Show inline comments
 
@@ -119,7 +119,11 @@ class InputStreamChunker(Thread):
 
        kr = self.keep_reading
 
        da = self.data_added
 
        go = self.go
 
        b = s.read(cs)
 

	
 
        try:
 
            b = s.read(cs)
 
        except ValueError:
 
            b = ''
 

	
 
        while b and go.is_set():
 
            if len(t) > ccm:
 
@@ -372,7 +376,9 @@ class SubprocessIOChunker(object):
 
            bg_out.stop()
 
            bg_err.stop()
 
            err = '%s' % ''.join(bg_err)
 
            raise EnvironmentError("Subprocess exited due to an error:\n" + err)
 
            if err:
 
                raise EnvironmentError("Subprocess exited due to an error:\n" + err)
 
            raise EnvironmentError("Subprocess exited with non 0 ret code:%s" % _returncode)
 

	
 
        self.process = _p
 
        self.output = bg_out
rhodecode/lib/utils.py
Show inline comments
 
@@ -748,7 +748,8 @@ def check_git_version():
 
    from rhodecode.lib.vcs.backends.git.repository import GitRepository
 
    from distutils.version import StrictVersion
 

	
 
    stdout, stderr = GitRepository._run_git_command('--version')
 
    stdout, stderr = GitRepository._run_git_command('--version', _bare=True,
 
                                                    _safe=True)
 

	
 
    ver = (stdout.split(' ')[-1] or '').strip() or '0.0.0'
 
    if len(ver.split('.')) > 3:
rhodecode/lib/vcs/backends/git/repository.py
Show inline comments
 
@@ -102,7 +102,17 @@ class GitRepository(BaseRepository):
 
        :param opts: env options to pass into Subprocess command
 
        """
 

	
 
        _copts = ['-c', 'core.quotepath=false', ]
 
        if '_bare' in opts:
 
            _copts = []
 
            del opts['_bare']
 
        else:
 
            _copts = ['-c', 'core.quotepath=false', ]
 
        safe_call = False
 
        if '_safe' in opts:
 
            #no exc on failure
 
            del opts['_safe']
 
            safe_call = True
 

	
 
        _str_cmd = False
 
        if isinstance(cmd, basestring):
 
            cmd = [cmd]
 
@@ -126,9 +136,13 @@ class GitRepository(BaseRepository):
 
            _opts.update(opts)
 
            p = subprocessio.SubprocessIOChunker(cmd, **_opts)
 
        except (EnvironmentError, OSError), err:
 
            log.error(traceback.format_exc())
 
            raise RepositoryError("Couldn't run git command (%s).\n"
 
                                  "Original error was:%s" % (cmd, err))
 
            tb_err = ("Couldn't run git command (%s).\n"
 
                      "Original error was:%s\n" % (cmd, err))
 
            log.error(tb_err)
 
            if safe_call:
 
                return '', err
 
            else:
 
                raise RepositoryError(tb_err)
 

	
 
        return ''.join(p.output), ''.join(p.error)
 

	
0 comments (0 inline, 0 general)