feat: force file sync while uploading file (#5668)
This commit is contained in:
committed by
GitHub
parent
94ec786d34
commit
4fd18a382c
@@ -280,6 +280,12 @@ func writeFile(afs afero.Fs, dst string, in io.Reader, fileMode, dirMode fs.File
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sync the file to ensure all data is written to storage.
|
||||||
|
// to prevent file corruption.
|
||||||
|
if err := file.Sync(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// Gets the info about the file.
|
// Gets the info about the file.
|
||||||
info, err := file.Stat()
|
info, err := file.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -256,6 +256,12 @@ func tusPatchHandler() handleFunc {
|
|||||||
return http.StatusInternalServerError, fmt.Errorf("could not write to file: %w", err)
|
return http.StatusInternalServerError, fmt.Errorf("could not write to file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sync the file to ensure all data is written to storage
|
||||||
|
// to prevent file corruption.
|
||||||
|
if err := openFile.Sync(); err != nil {
|
||||||
|
return http.StatusInternalServerError, fmt.Errorf("could not sync file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
newOffset := uploadOffset + bytesWritten
|
newOffset := uploadOffset + bytesWritten
|
||||||
w.Header().Set("Upload-Offset", strconv.FormatInt(newOffset, 10))
|
w.Header().Set("Upload-Offset", strconv.FormatInt(newOffset, 10))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user