mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-22 07:30:25 +00:00
simplify FileOpenFlags to os.Flags conversion
This commit is contained in:
parent
80b9c40489
commit
61b5a1d9a3
2 changed files with 7 additions and 8 deletions
|
@ -385,11 +385,12 @@ func (c Connection) handleSFTPUploadToExistingFile(pflags sftp.FileOpenFlags, re
|
||||||
return nil, sftp.ErrSshFxFailure
|
return nil, sftp.ErrSshFxFailure
|
||||||
}
|
}
|
||||||
|
|
||||||
osFlags, trunc := getOSOpenFlags(pflags)
|
osFlags := getOSOpenFlags(pflags)
|
||||||
|
|
||||||
if !trunc {
|
if osFlags&os.O_TRUNC == 0 {
|
||||||
// see https://github.com/pkg/sftp/issues/295
|
// see https://github.com/pkg/sftp/issues/295
|
||||||
logger.Info(logSender, "upload resume is not supported, returning error")
|
logger.Info(logSender, "upload resume is not supported, returning error for file: %v user: %v", requestPath,
|
||||||
|
c.User.Username)
|
||||||
return nil, sftp.ErrSshFxOpUnsupported
|
return nil, sftp.ErrSshFxOpUnsupported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -565,9 +566,8 @@ func (c Connection) createMissingDirs(filePath string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOSOpenFlags(requestFlags sftp.FileOpenFlags) (flags int, trunc bool) {
|
func getOSOpenFlags(requestFlags sftp.FileOpenFlags) (flags int) {
|
||||||
var osFlags int
|
var osFlags int
|
||||||
truncateFile := false
|
|
||||||
if requestFlags.Read && requestFlags.Write {
|
if requestFlags.Read && requestFlags.Write {
|
||||||
osFlags |= os.O_RDWR
|
osFlags |= os.O_RDWR
|
||||||
} else if requestFlags.Write {
|
} else if requestFlags.Write {
|
||||||
|
@ -581,12 +581,11 @@ func getOSOpenFlags(requestFlags sftp.FileOpenFlags) (flags int, trunc bool) {
|
||||||
}
|
}
|
||||||
if requestFlags.Trunc {
|
if requestFlags.Trunc {
|
||||||
osFlags |= os.O_TRUNC
|
osFlags |= os.O_TRUNC
|
||||||
truncateFile = true
|
|
||||||
}
|
}
|
||||||
if requestFlags.Excl {
|
if requestFlags.Excl {
|
||||||
osFlags |= os.O_EXCL
|
osFlags |= os.O_EXCL
|
||||||
}
|
}
|
||||||
return osFlags, truncateFile
|
return osFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUploadTempFilePath(path string) string {
|
func getUploadTempFilePath(path string) string {
|
||||||
|
|
|
@ -56,7 +56,7 @@ func TestGetOSOpenFlags(t *testing.T) {
|
||||||
flags.Write = true
|
flags.Write = true
|
||||||
flags.Append = true
|
flags.Append = true
|
||||||
flags.Excl = true
|
flags.Excl = true
|
||||||
osFlags, _ := getOSOpenFlags(flags)
|
osFlags := getOSOpenFlags(flags)
|
||||||
if osFlags&os.O_WRONLY == 0 || osFlags&os.O_APPEND == 0 || osFlags&os.O_EXCL == 0 {
|
if osFlags&os.O_WRONLY == 0 || osFlags&os.O_APPEND == 0 || osFlags&os.O_EXCL == 0 {
|
||||||
t.Errorf("error getting os flags from sftp file open flags")
|
t.Errorf("error getting os flags from sftp file open flags")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue