Skip to content

Commit e100bf1

Browse files
committed
#bug relative directory was calculated wrong
1 parent 0ec7485 commit e100bf1

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

cmd/afosto/files/upload.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func GetCommands() []*cobra.Command {
4242

4343
downloadCmd.Flags().StringP("source", "s", "", "")
4444
downloadCmd.Flags().StringP("destination", "d", "", "")
45+
downloadCmd.Flags().BoolP("private", "p", true, "")
4546

4647
return []*cobra.Command{uploadCmd, downloadCmd}
4748
}
@@ -95,27 +96,28 @@ func upload(cmd *cobra.Command, args []string) {
9596
destination = enteredDestination
9697
}
9798

99+
destination = strings.TrimRight(destination, "/") + "/"
100+
98101
queue := make(chan string, 25)
99102
uploader := sync.WaitGroup{}
100103
matcher := regexp.MustCompile(".*(jpe?g|png|svg|css|csv|js|txt|doc|eot|json|xls|xlsx|pdf|xml|mp4|mov|zip|md)$")
101104
uploader.Add(1)
102105
for i := 0; i < runtime.NumCPU(); i++ {
103-
go func() {
106+
go func(group *sync.WaitGroup) {
104107
for path := range queue {
108+
relativePath, err := filepath.Rel(source, path)
105109

106-
trimmedPath := path
107-
if idx := strings.LastIndex(trimmedPath, "/"); idx != -1 {
108-
trimmedPath = trimmedPath[0 : idx+1]
110+
if err != nil {
111+
logging.Log.Errorf("✗ failed to upload `%s`", path, err)
109112
}
110113

111-
relativePath := strings.TrimLeft(trimmedPath, source)
112-
replacer := strings.NewReplacer("//", "/")
113-
destinationDir := replacer.Replace(strings.Join([]string{destination, relativePath}, "/"))
114+
destinationPath := filepath.Dir(destination + relativePath)
114115

115-
signature, err := ac.GetSignature(destinationDir, "upsert")
116+
uploadAsPrivateFile, _ := cmd.Flags().GetBool("private")
117+
signature, err := ac.GetSignature(destinationPath, "upsert", uploadAsPrivateFile)
116118
if err != nil {
117-
logging.Log.Warnf("✗ failed to get a signature url for `%s`", destinationDir)
118-
return
119+
logging.Log.Warnf("✗ failed to get a signature url for `%s`", filepath.Dir(destinationPath))
120+
119121
}
120122

121123
file, err := ac.Upload(path, filepath.Base(path), signature)
@@ -124,10 +126,10 @@ func upload(cmd *cobra.Command, args []string) {
124126
} else {
125127
logging.Log.Infof("✔ Uploaded `%s` on url `%s`", file.Filename, file.Url)
126128
}
127-
uploader.Done()
129+
group.Done()
128130
}
129131

130-
}()
132+
}(&uploader)
131133
}
132134

133135
err = filepath.Walk(source,

pkg/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (ac *AfostoClient) GetTenant() (*data.Tenant, error) {
9696

9797
}
9898

99-
func (ac *AfostoClient) GetSignature(dir string, method string) (string, error) {
99+
func (ac *AfostoClient) GetSignature(dir string, method string, asPrivateDirectory bool) (string, error) {
100100
tenant, err := ac.GetTenant()
101101
if err != nil {
102102
return "", err
@@ -111,7 +111,7 @@ func (ac *AfostoClient) GetSignature(dir string, method string) (string, error)
111111
Method string `json:"method"`
112112
Metadata map[string]string `json:"metadata"`
113113
}{
114-
IsPublic: false,
114+
IsPublic: !asPrivateDirectory,
115115
IsListed: true,
116116
Path: dir,
117117
Method: method,

0 commit comments

Comments
 (0)