Skip to content

Commit

Permalink
download and upload
Browse files Browse the repository at this point in the history
  • Loading branch information
S Riemersma committed Sep 10, 2021
1 parent cd6e5b3 commit f9f76df
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
21 changes: 19 additions & 2 deletions cmd/afosto/files/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ 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"
"net/url"
"os"
"strings"
"sync"
"time"
)

func download(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions cmd/afosto/files/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit f9f76df

Please sign in to comment.