Skip to content

Commit

Permalink
Code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
guy-har committed Jul 11, 2024
1 parent c78a00e commit cf57a75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
21 changes: 12 additions & 9 deletions cmd/lakectl/cmd/fs_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,8 @@ var fsUploadCmd = &cobra.Command{

ctx, stop := signal.NotifyContext(ctx, os.Interrupt, os.Kill)
defer stop()
ignoreRecessive := true // Ignore recursive if source is the standard input or a file (not a directory)
if source != StdinFileName {
stat, err := os.Stat(source)
if err != nil {
Die("failed to stat source", 1)
}
ignoreRecessive = !stat.IsDir()
}

if !recursive || ignoreRecessive {
if !recursive || isFileOrStdin(source) {
if strings.HasSuffix(remotePath, uri.PathSeparator) {
Die("target path is not a valid URI", 1)
}
Expand Down Expand Up @@ -88,6 +80,17 @@ var fsUploadCmd = &cobra.Command{
},
}

func isFileOrStdin(source string) bool {
if source == StdinFileName {
return true
}
stat, err := os.Stat(source)
if err != nil {
Die("failed to stat source", 1)
}
return !stat.IsDir()
}

func upload(ctx context.Context, client apigen.ClientWithResponsesInterface, sourcePathname string, destURI *uri.URI, contentType string, syncFlags local.SyncFlags) (*apigen.ObjectStats, error) {
fp := Must(OpenByPath(sourcePathname))
defer func() {
Expand Down
4 changes: 3 additions & 1 deletion esti/lakectl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ func TestLakectlPreSignUpload(t *testing.T) {
})
t.Run("upload from stdin", func(t *testing.T) {
filePath = "sample"
RunCmdAndVerifySuccess(t, "echo sample | "+Lakectl()+" -c ~/.lakectl.yaml fs upload -s - lakefs://"+repoName+"/"+mainBranch+"/"+filePath+" --pre-sign", false, "sample", vars)
fileContent := "sample"
expected := sanitize(fileContent, vars)
RunCmdAndVerifySuccess(t, "echo sample | "+Lakectl()+" fs upload -s - lakefs://"+repoName+"/"+mainBranch+"/"+filePath+" --pre-sign", false, expected, vars)
})
}

Expand Down

0 comments on commit cf57a75

Please sign in to comment.