From a3203ab03a1124036191079e0acf3d7ff04fe234 Mon Sep 17 00:00:00 2001 From: brent s Date: Tue, 7 Jul 2020 13:32:02 -0400 Subject: [PATCH] fix reporting zero exit for rsync as non-zero would give warning output like the following: /usr/local/lib/repomirror/repomirror/fetcher/rsync.py:78: UserWarning: Rsync process returned non-zero 0 (Success) for rsync --recursive --times --links --hard-links --delete-after --delay-updates --copy-links --safe-links --delete-excluded --no-motd --exclude=.* --verbose --log-file-format="[RSYNC arch.mirror.constant.com:873]:%l:%f%L" --log-file=/var/log/repo/arch.log rsync://arch.mirror.constant.com:873/archlinux/. /srv/repos/arch/. --- repomirror/constants.py | 3 ++- repomirror/fetcher/rsync.py | 30 ++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/repomirror/constants.py b/repomirror/constants.py index 239e2e6..d11525a 100644 --- a/repomirror/constants.py +++ b/repomirror/constants.py @@ -11,5 +11,6 @@ RSYNC_DEF_ARGS = ['--recursive', '--delete-excluded', '--exclude=.*'] # How many days an upstream should have last synced by before it's considered stale. +## TODO: make this part of the upstream config? repo config? DAYS_WARN = 2 -VERSION = '1.0.3' +VERSION = '1.0.4' diff --git a/repomirror/fetcher/rsync.py b/repomirror/fetcher/rsync.py index 1a0e861..93d63dd 100644 --- a/repomirror/fetcher/rsync.py +++ b/repomirror/fetcher/rsync.py @@ -73,9 +73,18 @@ class RSync(_base.BaseFetcher): if stderr != '' or cmd.returncode != 0: rtrn = cmd.returncode err = rsync_returns.returns[rtrn] - _logger.error(('Rsync to {0}:{1} returned exit status {2}: {3}').format(self.domain, self.port, rtrn, err)) - _logger.debug('STDERR: {0}'.format(stderr)) - warnings.warn('Rsync process returned non-zero {0} ({1}) for {2}'.format(rtrn, err, ' '.join(cmd_str))) + errmsg = 'Rsync to {0}:{1} returned'.format(self.domain, self.port) + debugmsg = 'Rsync command {0} returned'.format(' '.join(cmd_str)) + if stderr != '': + errmsg += ' an error message: {0}'.format(stderr) + debugmsg += ' an error message: {0}'.format(stderr) + if rtrn != 0: + errmsg += ' with exit status {0} ({1})'.format(rtrn, err) + debugmsg += ' with exit status {0} ({1})'.format(rtrn, err) + errmsg += '.' + _logger.error(errmsg) + _logger.debug(debugmsg) + warnings.warn(errmsg) return(None) def fetch_content(self, remote_filepath): @@ -96,9 +105,18 @@ class RSync(_base.BaseFetcher): if stderr != '' or cmd.returncode != 0: rtrn = cmd.returncode err = rsync_returns.returns[rtrn] - _logger.error(('Rsync to {0}:{1} returned exit status {2}: {3}').format(self.domain, self.port, rtrn, err)) - _logger.debug('STDERR: {0}'.format(stderr)) - warnings.warn('Rsync process returned non-zero {0} ({1}) for {2}'.format(rtrn, err, ' '.join(cmd_str))) + errmsg = 'Rsync to {0}:{1} returned'.format(self.domain, self.port) + debugmsg = 'Rsync command {0} returned'.format(' '.join(cmd_str)) + if stderr != '': + errmsg += ' an error message: {0}'.format(stderr) + debugmsg += ' an error message: {0}'.format(stderr) + if rtrn != 0: + errmsg += ' with exit status {0} ({1})'.format(rtrn, err) + debugmsg += ' with exit status {0} ({1})'.format(rtrn, err) + errmsg += '.' + _logger.error(errmsg) + _logger.debug(debugmsg) + warnings.warn(errmsg) with open(tf, 'rb') as fh: raw_content = fh.read() os.remove(tf)