mirror of
https://github.com/rclone/rclone.git
synced 2025-06-05 20:34:39 +08:00
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:

committed by
Nick Craig-Wood

parent
e2bf91452a
commit
53874bd8ee
@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user