From 0a2967ef53af5208b1ed5dd894a8168b854b6334 Mon Sep 17 00:00:00 2001 From: Alex Aperis Date: Fri, 8 Dec 2023 14:23:31 +0100 Subject: [PATCH] skip listing files if force-overwrite --- upload/upload.go | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/upload/upload.go b/upload/upload.go index 95f1b88c..7b44b2fa 100644 --- a/upload/upload.go +++ b/upload/upload.go @@ -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") } }