Skip to content

Commit

Permalink
skip listing files if force-overwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
aaperis committed Dec 8, 2023
1 parent f1c731d commit 0a2967e
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,23 @@ func uploadFiles(files, outFiles []string, targetDir string, config *helpers.Con
return err
}

// Check if files exists in S3
var listPrefix string
if targetDir != "" {
listPrefix = targetDir + "/" + outFiles[k]
if *forceOverwrite {
fmt.Println("force-overwrite flag provided, continuing...")
} else {
listPrefix = outFiles[k]
}
fileExists, err := helpers.ListFiles(*config, listPrefix)
if err != nil {
return fmt.Errorf("listing uploaded files: %s", err.Error())
}
if len(fileExists.Contents) > 0 {
if aws.StringValue(fileExists.Contents[0].Key) == filepath.Clean(config.AccessKey+"/"+targetDir+"/"+outFiles[k]) {
// Check if files exists in S3
listPrefix := outFiles[k]
if targetDir != "" {
listPrefix = targetDir + "/" + outFiles[k]
}

fileExists, err := helpers.ListFiles(*config, listPrefix)
if err != nil {
return fmt.Errorf("listing uploaded files: %s", err.Error())
}
if len(fileExists.Contents) > 0 && aws.StringValue(fileExists.Contents[0].Key) == filepath.Clean(config.AccessKey+"/"+targetDir+"/"+outFiles[k]) {
fmt.Printf("File %s is already uploaded!\n", filepath.Base(filename))
if !*forceOverwrite {
fmt.Println("Quitting...")

return errors.New("file already uploaded")
}
fmt.Println("force-overwrite flag provided, continuing...")
return errors.New("file already uploaded")
}
}

Expand Down

0 comments on commit 0a2967e

Please sign in to comment.