add support for atomic upload

Atomic uploads are now configurable. The default upload mode remains
non atomic
This commit is contained in:
Nicola Murino
2019-08-04 09:37:58 +02:00
parent d2361da570
commit 80b9c40489
12 changed files with 319 additions and 94 deletions

View File

@@ -43,6 +43,11 @@ type Configuration struct {
MaxAuthTries int `json:"max_auth_tries"`
// Umask for new files
Umask string `json:"umask"`
// UploadMode 0 means standard, the files are uploaded directly to the requested path.
// 1 means atomic: the files are uploaded to a temporary path and renamed to the requested path
// when the client ends the upload. Atomic mode avoid problems such as a web server that
// serves partial files when the files are being uploaded.
UploadMode int `json:"upload_mode"`
// Actions to execute on SFTP create, download, delete and rename
Actions Actions `json:"actions"`
// Keys are a list of host keys
@@ -119,6 +124,7 @@ func (c Configuration) Initialize(configDir string) error {
}
actions = c.Actions
uploadMode = c.UploadMode
logger.Info(logSender, "server listener registered address: %v", listener.Addr().String())
if c.IdleTimeout > 0 {
startIdleTimer(time.Duration(c.IdleTimeout) * time.Minute)