mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 14:50:55 +03:00
S3: fix quota update after an upload error
S3 uploads are atomic, if the upload fails we have no partial file so we have to update the user quota only if the upload succeed
This commit is contained in:
@@ -479,11 +479,16 @@ func (c Connection) handleSFTPUploadToExistingFile(pflags sftp.FileOpenFlags, re
|
||||
return nil, vfs.GetSFTPError(c.fs, err)
|
||||
}
|
||||
|
||||
initialSize := int64(0)
|
||||
if pflags.Append && osFlags&os.O_TRUNC == 0 {
|
||||
c.Log(logger.LevelDebug, logSender, "upload resume requested, file path: %#v initial size: %v", filePath, fileSize)
|
||||
minWriteOffset = fileSize
|
||||
} else {
|
||||
dataprovider.UpdateUserQuota(dataProvider, c.User, 0, -fileSize, false)
|
||||
if vfs.IsLocalOsFs(c.fs) {
|
||||
dataprovider.UpdateUserQuota(dataProvider, c.User, 0, -fileSize, false)
|
||||
} else {
|
||||
initialSize = fileSize
|
||||
}
|
||||
}
|
||||
|
||||
vfs.SetPathPermissions(c.fs, filePath, c.User.GetUID(), c.User.GetGID())
|
||||
@@ -506,6 +511,7 @@ func (c Connection) handleSFTPUploadToExistingFile(pflags sftp.FileOpenFlags, re
|
||||
transferError: nil,
|
||||
isFinished: false,
|
||||
minWriteOffset: minWriteOffset,
|
||||
initialSize: initialSize,
|
||||
lock: new(sync.Mutex),
|
||||
}
|
||||
addTransfer(&transfer)
|
||||
|
||||
Reference in New Issue
Block a user