Skip to content

Commit

Permalink
Call sync after each localstorage write (#58)
Browse files Browse the repository at this point in the history
* Call sync after each localstorage write

* Check file syncing error
  • Loading branch information
jademcosta committed Aug 7, 2023
1 parent f4edb17 commit 55ff3a7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/adapters/objstorage/localstorage/localstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,22 @@ func (storage *LocalStorage) Upload(workU *domain.WorkUnit) (*domain.UploadResul

fullFilePath := filepath.Join(storage.path, workU.Prefix, workU.Filename)

err = os.WriteFile(fullFilePath, workU.Data, os.ModePerm)
file, err := os.Create(fullFilePath)
if err != nil {
return nil, fmt.Errorf("error creating file: %w", err)
}
defer file.Close()

_, err = file.Write(workU.Data)
if err != nil {
return nil, fmt.Errorf("error writing data into file: %w", err)
}

err = file.Sync()
if err != nil {
return nil, fmt.Errorf("error when syncing file: %w", err)
}

return &domain.UploadResult{
Bucket: "localstorage",
Path: fullFilePath,
Expand Down

0 comments on commit 55ff3a7

Please sign in to comment.