sftpd transfer: close the file before executing any action ...

... that could potentially move or delete it
This commit is contained in:
Nicola Murino 2019-07-27 11:17:32 +02:00
parent 6a6e31cceb
commit 25f7043fb3

View file

@ -47,6 +47,7 @@ func (t *Transfer) WriteAt(p []byte, off int64) (n int, err error) {
// Close method called when the transfer is completed, we log the transfer info // Close method called when the transfer is completed, we log the transfer info
func (t *Transfer) Close() error { func (t *Transfer) Close() error {
err := t.file.Close()
elapsed := time.Since(t.start).Nanoseconds() / 1000000 elapsed := time.Since(t.start).Nanoseconds() / 1000000
if t.transferType == transferDownload { if t.transferType == transferDownload {
logger.TransferLog(sftpdDownloadLogSender, t.path, elapsed, t.bytesSent, t.user.Username, t.connectionID) logger.TransferLog(sftpdDownloadLogSender, t.path, elapsed, t.bytesSent, t.user.Username, t.connectionID)
@ -61,7 +62,7 @@ func (t *Transfer) Close() error {
numFiles++ numFiles++
dataprovider.UpdateUserQuota(dataProvider, t.user.Username, numFiles, t.bytesReceived, false) dataprovider.UpdateUserQuota(dataProvider, t.user.Username, numFiles, t.bytesReceived, false)
} }
return t.file.Close() return err
} }
func (t *Transfer) handleThrottle() { func (t *Transfer) handleThrottle() {