#!/usr/bin/env bash

# Copyright (C) 2015-2019 Maciej Delmanowski <drybjed@gmail.com>
# Copyright (C) 2015-2019 DebOps <https://debops.org/>
# SPDX-License-Identifier: GPL-3.0-only

# Use this script instead of /usr/bin/rsync command to avoid issues with
# vanishing files.
# https://bugzilla.samba.org/show_bug.cgi?id=3653

IGNOREEXIT=24
IGNOREOUT='^(file has vanished: |rsync warning: some files vanished before they could be transferred)'

set -o pipefail

rsync "${@}" 2>&1 | (grep -v -E "$IGNOREOUT" || true)
ret=$?

if [[ $ret == "$IGNOREEXIT" ]]; then
    ret=0
fi

exit $ret
