sftpd: add support for excluding virtual folders from user quota limit

Fixes #110
This commit is contained in:
Nicola Murino
2020-05-01 15:27:53 +02:00
parent 14c2a244b7
commit 3f75d46a16
16 changed files with 340 additions and 139 deletions

View File

@@ -26,26 +26,27 @@ var (
// Transfer contains the transfer details for an upload or a download.
// It implements the io Reader and Writer interface to handle files downloads and uploads
type Transfer struct {
file *os.File
writerAt *pipeat.PipeWriterAt
readerAt *pipeat.PipeReaderAt
cancelFn func()
path string
start time.Time
bytesSent int64
bytesReceived int64
user dataprovider.User
connectionID string
transferType int
lastActivity time.Time
protocol string
transferError error
minWriteOffset int64
expectedSize int64
initialSize int64
lock *sync.Mutex
isNewFile bool
isFinished bool
file *os.File
writerAt *pipeat.PipeWriterAt
readerAt *pipeat.PipeReaderAt
cancelFn func()
path string
start time.Time
bytesSent int64
bytesReceived int64
user dataprovider.User
connectionID string
transferType int
lastActivity time.Time
protocol string
transferError error
minWriteOffset int64
expectedSize int64
initialSize int64
lock *sync.Mutex
isNewFile bool
isFinished bool
isExcludedFromQuota bool
}
// TransferError is called if there is an unexpected error.
@@ -184,6 +185,9 @@ func (t *Transfer) updateQuota(numFiles int) bool {
if t.file == nil && t.transferError != nil {
return false
}
if t.isExcludedFromQuota {
return false
}
if t.transferType == transferUpload && (numFiles != 0 || t.bytesReceived > 0) {
dataprovider.UpdateUserQuota(dataProvider, t.user, numFiles, t.bytesReceived-t.initialSize, false) //nolint:errcheck
return true