Skip to content

Commit cf8dc6f

Browse files
committed
add delete after upload option
1 parent b7400fd commit cf8dc6f

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Options:
3535
Maximum number of parallel uploads [default: 5, env: S3U_PARALLELUPLOADS]
3636
--upload-queue-size UPLOAD-QUEUE-SIZE
3737
Size for upload queue; should larger as the expected amount of files that change per check cycle [default: 50, env: S3U_UPLOADQUEUESIZE]
38+
--delete-after-upload
39+
Delete files on local disk after successful upload [env: S3U_DELETEAFTERUPLOAD]
3840
--s3-region S3-REGION
3941
S3 region of the upload bucket [env: S3U_S3_REGION]
4042
--s3-bucket S3-BUCKET

cmd/s3-uploader/main.go

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ type Args struct {
2323
ParallelUploads int `arg:"--parallel-uploads,env:S3U_PARALLELUPLOADS" default:"5" help:"Maximum number of parallel uploads"`
2424
UploadQueueSize int `arg:"--upload-queue-size,env:S3U_UPLOADQUEUESIZE" default:"50" help:"Size for upload queue; should larger as the expected amount of files that change per check cycle"`
2525

26+
DeleteAfterUpload bool `arg:"--delete-after-upload,env:S3U_DELETEAFTERUPLOAD" help:"Delete files on local disk after successful upload"`
27+
2628
S3Region string `arg:"--s3-region,env:S3U_S3_REGION,required" help:"S3 region of the upload bucket"`
2729
S3Bucket string `arg:"--s3-bucket,env:S3U_S3_BUCKET,required" help:"S3 bucket to upload to"`
2830
S3Endpoint *string `arg:"--s3-endpoint,env:S3U_S3_ENDPOINT" help:"S3 endpoint URL"`
@@ -74,6 +76,14 @@ func main() {
7476
}
7577

7678
slog.Info("upload finished", "path", fullPath, "key", key)
79+
80+
if args.DeleteAfterUpload {
81+
err := os.Remove(fullPath)
82+
if err != nil {
83+
slog.Error("failed to delete file", "path", fullPath, "err", err)
84+
}
85+
slog.Info("deleted file", "path", fullPath, "key", key)
86+
}
7787
})
7888
}
7989
}

0 commit comments

Comments
 (0)