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/.
This commit is contained in:
brent s. 2020-07-07 13:32:02 -04:00
parent 6d384e71ae
commit a3203ab03a
Signed by: bts
GPG Key ID: 8C004C2F93481F6B
2 changed files with 26 additions and 7 deletions

View File

@ -11,5 +11,6 @@ RSYNC_DEF_ARGS = ['--recursive',
'--delete-excluded', '--delete-excluded',
'--exclude=.*'] '--exclude=.*']
# How many days an upstream should have last synced by before it's considered stale. # 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 DAYS_WARN = 2
VERSION = '1.0.3' VERSION = '1.0.4'

View File

@ -73,9 +73,18 @@ class RSync(_base.BaseFetcher):
if stderr != '' or cmd.returncode != 0: if stderr != '' or cmd.returncode != 0:
rtrn = cmd.returncode rtrn = cmd.returncode
err = rsync_returns.returns[rtrn] err = rsync_returns.returns[rtrn]
_logger.error(('Rsync to {0}:{1} returned exit status {2}: {3}').format(self.domain, self.port, rtrn, err)) errmsg = 'Rsync to {0}:{1} returned'.format(self.domain, self.port)
_logger.debug('STDERR: {0}'.format(stderr)) debugmsg = 'Rsync command {0} returned'.format(' '.join(cmd_str))
warnings.warn('Rsync process returned non-zero {0} ({1}) for {2}'.format(rtrn, err, ' '.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) return(None)


def fetch_content(self, remote_filepath): def fetch_content(self, remote_filepath):
@ -96,9 +105,18 @@ class RSync(_base.BaseFetcher):
if stderr != '' or cmd.returncode != 0: if stderr != '' or cmd.returncode != 0:
rtrn = cmd.returncode rtrn = cmd.returncode
err = rsync_returns.returns[rtrn] err = rsync_returns.returns[rtrn]
_logger.error(('Rsync to {0}:{1} returned exit status {2}: {3}').format(self.domain, self.port, rtrn, err)) errmsg = 'Rsync to {0}:{1} returned'.format(self.domain, self.port)
_logger.debug('STDERR: {0}'.format(stderr)) debugmsg = 'Rsync command {0} returned'.format(' '.join(cmd_str))
warnings.warn('Rsync process returned non-zero {0} ({1}) for {2}'.format(rtrn, err, ' '.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: with open(tf, 'rb') as fh:
raw_content = fh.read() raw_content = fh.read()
os.remove(tf) os.remove(tf)