Creating a sparse file, because on file create an inotify will produce an event and dir size will be recalculated, so it can get an actual size.
This commit is contained in:
parent
ddaf2bb991
commit
bf0595453c
@ -136,6 +136,14 @@ func (h *UploadHandlers) Upload(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
defer fDst.Close()
|
||||
|
||||
// We initialy set a dst file size to occupy space equal to uploaded's size.
|
||||
// This is called a sparse file, if you need to know.
|
||||
// It allows us to have a relatively small buffer size for inotify watcher.
|
||||
// And it really affects that. I tested it.
|
||||
fDst.Seek(fHandler.Size-1, io.SeekStart)
|
||||
fDst.Write([]byte{0})
|
||||
fDst.Seek(0, io.SeekStart)
|
||||
|
||||
_, err = io.Copy(fDst, f)
|
||||
if err != nil {
|
||||
h.logErr.Println("failed to copy uploaded file to destination:", err)
|
||||
|
Loading…
Reference in New Issue
Block a user