cmd: add --error-on-no-transfer option

This allows rclone to exit with a non-zero return code if no files are
transferred. This is useful when calling rclone as part of a workflow/script
pipeline as it allows the end user to stop processing if no files have been
transferred.

NB: Enabling this option will return in rclone exiting non-zero if there are no
transfers. Depending on how your're currently using rclone in your scripts,
this may break existing setups!
This commit is contained in:
Jon Fautley 2019-12-18 11:52:20 +00:00 committed by Nick Craig-Wood
parent e2bf91452a
commit 53874bd8ee
4 changed files with 22 additions and 0 deletions

View file

@ -66,6 +66,7 @@ const (
exitCodeNoRetryError
exitCodeFatalError
exitCodeTransferExceeded
exitCodeNoFilesTransferred
)
// ShowVersion prints the version to stdout
@ -312,6 +313,7 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
}
}
resolveExitCode(cmdErr)
}
// CheckArgs checks there are enough arguments and prints a message if not
@ -430,6 +432,11 @@ func initConfig() {
func resolveExitCode(err error) {
atexit.Run()
if err == nil {
if fs.Config.ErrorOnNoTransfer {
if accounting.GlobalStats().GetTransfers() == 0 {
os.Exit(exitCodeNoFilesTransferred)
}
}
os.Exit(exitCodeSuccess)
}