Skip to content

Commit

Permalink
fix: auto create bucket when uploading file recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Oct 24, 2023
1 parent 3f0e2d0 commit 691eff6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var (

cpCmd = &cobra.Command{
Use: "cp <src> <dst>",
Example: `cp readme.md ss:///bucket
Example: `cp readme.md ss:///bucket/readme.md
cp -r docs ss:///bucket/docs
cp -r ss:///bucket/docs .
`,
Expand Down
7 changes: 4 additions & 3 deletions internal/storage/cp/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func UploadStorageObjectAll(ctx context.Context, projectRef, remotePath, localPa
dstPath := remotePath
// Copying single file
if relPath == "." {
if IsDir(dstPath) || (dirExists && !fileExists) {
_, prefix := storage.SplitBucketPrefix(dstPath)
if IsDir(prefix) || (dirExists && !fileExists) {
dstPath = path.Join(dstPath, info.Name())
}
} else {
Expand All @@ -132,6 +133,6 @@ func UploadStorageObjectAll(ctx context.Context, projectRef, remotePath, localPa
})
}

func IsDir(objectPath string) bool {
return len(objectPath) == 0 || strings.HasSuffix(objectPath, "/")
func IsDir(objectPrefix string) bool {
return len(objectPrefix) == 0 || strings.HasSuffix(objectPrefix, "/")
}

0 comments on commit 691eff6

Please sign in to comment.