Compare commits
No commits in common. "cdaf3d081e8141ad2875264f643d7d90187c704a" and "8bde3ccb909aa8da761aa96cc3ac79504b6164b3" have entirely different histories.
cdaf3d081e
...
8bde3ccb90
20
main.go
20
main.go
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
@ -22,7 +21,6 @@ func main() {
|
|||
directory := flag.String("directory", "", "Directory in the S3 bucket to upload the file to")
|
||||
listFiles := flag.Bool("list", false, "List files in the S3 bucket")
|
||||
deleteFile := flag.String("delete", "", "Path to the file to delete from the S3 bucket")
|
||||
overwrite := flag.Bool("overwrite", false, "Overwrite the file if it already exists on S3")
|
||||
flag.Parse()
|
||||
|
||||
if *configPath == "" {
|
||||
|
@ -94,7 +92,6 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Check if the file exists before attempting to open it
|
||||
if _, err := os.Stat(*filePath); os.IsNotExist(err) {
|
||||
fmt.Printf("File does not exist: %s\n", *filePath)
|
||||
os.Exit(1)
|
||||
|
@ -116,23 +113,6 @@ func main() {
|
|||
}
|
||||
key = filepath.ToSlash(key)
|
||||
|
||||
// Check if the file already exists on S3
|
||||
headObjectInput := &s3.HeadObjectInput{
|
||||
Bucket: aws.String(bucket),
|
||||
Key: aws.String(key),
|
||||
}
|
||||
_, err = svc.HeadObject(headObjectInput)
|
||||
if err == nil && !*overwrite {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
fmt.Printf("The file with the same filename already exists on S3. Do you want to overwrite? [y/n] > ")
|
||||
response, _ := reader.ReadString('\n')
|
||||
response = strings.TrimSpace(response)
|
||||
if strings.ToLower(response) != "y" {
|
||||
fmt.Println("Upload cancelled.")
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
_, err = svc.PutObject(&s3.PutObjectInput{
|
||||
Bucket: aws.String(bucket),
|
||||
Key: aws.String(key),
|
||||
|
|
Loading…
Reference in New Issue
Block a user