Skip to content

Commit

Permalink
s3_monitor: download with .tmp prefix and rename, to play nicely with…
Browse files Browse the repository at this point in the history
… fsnotify
  • Loading branch information
dezeroku committed Oct 2, 2024
1 parent 74c93d0 commit 601cbd0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions s3_monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,15 @@ func main() {
}

objectKey := event.Detail.Object.Key
fileName := objectKey + addedObjectSuffix
filePath := path.Join(storagePath, objectKey+addedObjectSuffix)
filePathTmp := filePath + ".tmp"

if err := DownloadFile(s3Client, bucketName, objectKey, path.Join(storagePath, fileName)); err != nil {
// Write to a .tmp file first and rename later on, to play nicely with fsnotify
// and ensure that write is complete
if err := DownloadFile(s3Client, bucketName, objectKey, path.Join(storagePath, filePathTmp)); err != nil {
log.Fatal(err)
}
if err := os.Rename(filePathTmp, filePath); err != nil {
log.Fatal(err)
}

Expand Down

0 comments on commit 601cbd0

Please sign in to comment.