1
0

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:
Alexander Andreev 2022-02-08 02:12:01 +04:00
parent ddaf2bb991
commit bf0595453c
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

View File

@ -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)