Compare commits

..

No commits in common. "55bc83b82bf3af96e2923f2bc924929a550dc316" and "b9836c393d30c62e7e950f3c9df240e93d86aaf1" have entirely different histories.

2 changed files with 1 additions and 33 deletions

3
.gitignore vendored
View File

@ -1,2 +1 @@
s3config.toml s3config.toml
s3-client-dev

31
main.go
View File

@ -20,7 +20,6 @@ func main() {
configPath := flag.String("config", "", "Path to the configuration file") configPath := flag.String("config", "", "Path to the configuration file")
directory := flag.String("directory", "", "Directory in the S3 bucket to upload the file to") 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") 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")
flag.Parse() flag.Parse()
if *configPath == "" { if *configPath == "" {
@ -81,11 +80,6 @@ func main() {
return return
} }
if *deleteFile != "" {
deleteS3File(svc, bucket, *deleteFile)
return
}
if *filePath == "" { if *filePath == "" {
fmt.Println("No file specified for upload. Use -file to specify a file or -list to list bucket contents.") fmt.Println("No file specified for upload. Use -file to specify a file or -list to list bucket contents.")
fmt.Println("Use -help for more information") fmt.Println("Use -help for more information")
@ -147,28 +141,3 @@ func listBucketFiles(svc *s3.S3, bucket string) {
os.Exit(1) os.Exit(1)
} }
} }
func deleteS3File(svc *s3.S3, bucket, filePath string) {
filePath = strings.TrimPrefix(filePath, "/")
_, err := svc.DeleteObject(&s3.DeleteObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(filePath),
})
if err != nil {
fmt.Printf("Error deleting file from S3: %s\n", err)
os.Exit(1)
}
err = svc.WaitUntilObjectNotExists(&s3.HeadObjectInput{
Bucket: aws.String(bucket),
Key: aws.String(filePath),
})
if err != nil {
fmt.Printf("Error waiting for file deletion: %s\n", err)
os.Exit(1)
}
fmt.Printf("Successfully deleted file: %s\n", filePath)
}