diff --git a/cmd/afosto/files/download.go b/cmd/afosto/files/download.go index e1c1ca3..6c8097f 100644 --- a/cmd/afosto/files/download.go +++ b/cmd/afosto/files/download.go @@ -5,6 +5,7 @@ import ( "github.com/afosto/cli/pkg/client" "github.com/afosto/cli/pkg/data" "github.com/afosto/cli/pkg/logging" + "github.com/cenkalti/backoff/v4" "github.com/gen2brain/dlgs" "github.com/spf13/cobra" "io/ioutil" @@ -12,6 +13,7 @@ import ( "os" "strings" "sync" + "time" ) func download(cmd *cobra.Command, args []string) { @@ -71,10 +73,25 @@ func download(cmd *cobra.Command, args []string) { go downloadHandler(downloadQueue, ac, source, destination, &wg) logging.Log.Infof("✔ Started listing Directories`") - directories, err := ac.ListDirectories(source) - if err != nil { + + b := backoff.NewExponentialBackOff() + b.MaxElapsedTime = time.Second * 600 + b.MaxInterval = time.Second * 50 + + var directories = []string{} + + if err := backoff.RetryNotify(func() error { + var err error + directories, err = ac.ListDirectories(source) + + return err + + }, backoff.WithMaxRetries(b, 5), func(err error, duration time.Duration) { + logging.Log.WithField("retrying in", duration).Warn(err) + }); err != nil { logging.Log.Fatal(err) } + logging.Log.Infof("✔ Finished listing directories`") for _, directory := range directories { diff --git a/cmd/afosto/files/upload.go b/cmd/afosto/files/upload.go index 3e12d49..fbcb75a 100644 --- a/cmd/afosto/files/upload.go +++ b/cmd/afosto/files/upload.go @@ -112,6 +112,8 @@ func upload(cmd *cobra.Command, args []string) { destinationPath := filepath.Dir(destination + relativePath) + //replace path for windows + destinationPath = strings.ReplaceAll(destinationPath, "\\", "/") uploadAsPrivateFile, _ := cmd.Flags().GetBool("private") signature, err := ac.GetSignature(destinationPath, "upsert", uploadAsPrivateFile) if err != nil { diff --git a/go.mod b/go.mod index 0186b4b..84d4fd7 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/afosto/cli go 1.13 require ( + github.com/cenkalti/backoff/v4 v4.1.1 github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/flosch/pongo2/v4 v4.0.2 github.com/gen2brain/dlgs v0.0.0-20210406143744-f512297a108e diff --git a/go.sum b/go.sum index 1648ef5..4b7b9f9 100644 --- a/go.sum +++ b/go.sum @@ -23,6 +23,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= +github.com/cenkalti/backoff/v4 v4.1.1 h1:G2HAfAmvm/GcKan2oOQpBXOd2tT2G57ZnZGWa1PxPBQ= +github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=