mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-08 07:10:56 +03:00
GCS uploads: check Close() error
some code simplification too
This commit is contained in:
@@ -458,12 +458,7 @@ func (c *BaseConnection) ignoreSetStat() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetStat set StatAttributes for the specified fsPath
|
func (c *BaseConnection) handleChmod(fsPath, pathForPerms string, attributes *StatAttributes) error {
|
||||||
// nolint:gocyclo
|
|
||||||
func (c *BaseConnection) SetStat(fsPath, virtualPath string, attributes *StatAttributes) error {
|
|
||||||
pathForPerms := c.getPathForSetStatPerms(fsPath, virtualPath)
|
|
||||||
|
|
||||||
if attributes.Flags&StatAttrPerms != 0 {
|
|
||||||
if !c.User.HasPerm(dataprovider.PermChmod, pathForPerms) {
|
if !c.User.HasPerm(dataprovider.PermChmod, pathForPerms) {
|
||||||
return c.GetPermissionDeniedError()
|
return c.GetPermissionDeniedError()
|
||||||
}
|
}
|
||||||
@@ -476,9 +471,10 @@ func (c *BaseConnection) SetStat(fsPath, virtualPath string, attributes *StatAtt
|
|||||||
}
|
}
|
||||||
logger.CommandLog(chmodLogSender, fsPath, "", c.User.Username, attributes.Mode.String(), c.ID, c.protocol,
|
logger.CommandLog(chmodLogSender, fsPath, "", c.User.Username, attributes.Mode.String(), c.ID, c.protocol,
|
||||||
-1, -1, "", "", "", -1)
|
-1, -1, "", "", "", -1)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if attributes.Flags&StatAttrUIDGID != 0 {
|
func (c *BaseConnection) handleChown(fsPath, pathForPerms string, attributes *StatAttributes) error {
|
||||||
if !c.User.HasPerm(dataprovider.PermChown, pathForPerms) {
|
if !c.User.HasPerm(dataprovider.PermChown, pathForPerms) {
|
||||||
return c.GetPermissionDeniedError()
|
return c.GetPermissionDeniedError()
|
||||||
}
|
}
|
||||||
@@ -492,9 +488,10 @@ func (c *BaseConnection) SetStat(fsPath, virtualPath string, attributes *StatAtt
|
|||||||
}
|
}
|
||||||
logger.CommandLog(chownLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, attributes.UID, attributes.GID,
|
logger.CommandLog(chownLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, attributes.UID, attributes.GID,
|
||||||
"", "", "", -1)
|
"", "", "", -1)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if attributes.Flags&StatAttrTimes != 0 {
|
func (c *BaseConnection) handleChtimes(fsPath, pathForPerms string, attributes *StatAttributes) error {
|
||||||
if !c.User.HasPerm(dataprovider.PermChtimes, pathForPerms) {
|
if !c.User.HasPerm(dataprovider.PermChtimes, pathForPerms) {
|
||||||
return c.GetPermissionDeniedError()
|
return c.GetPermissionDeniedError()
|
||||||
}
|
}
|
||||||
@@ -510,6 +507,23 @@ func (c *BaseConnection) SetStat(fsPath, virtualPath string, attributes *StatAtt
|
|||||||
modificationTimeString := attributes.Mtime.Format(chtimesFormat)
|
modificationTimeString := attributes.Mtime.Format(chtimesFormat)
|
||||||
logger.CommandLog(chtimesLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1,
|
logger.CommandLog(chtimesLogSender, fsPath, "", c.User.Username, "", c.ID, c.protocol, -1, -1,
|
||||||
accessTimeString, modificationTimeString, "", -1)
|
accessTimeString, modificationTimeString, "", -1)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStat set StatAttributes for the specified fsPath
|
||||||
|
func (c *BaseConnection) SetStat(fsPath, virtualPath string, attributes *StatAttributes) error {
|
||||||
|
pathForPerms := c.getPathForSetStatPerms(fsPath, virtualPath)
|
||||||
|
|
||||||
|
if attributes.Flags&StatAttrPerms != 0 {
|
||||||
|
return c.handleChmod(fsPath, pathForPerms, attributes)
|
||||||
|
}
|
||||||
|
|
||||||
|
if attributes.Flags&StatAttrUIDGID != 0 {
|
||||||
|
return c.handleChown(fsPath, pathForPerms, attributes)
|
||||||
|
}
|
||||||
|
|
||||||
|
if attributes.Flags&StatAttrTimes != 0 {
|
||||||
|
return c.handleChtimes(fsPath, pathForPerms, attributes)
|
||||||
}
|
}
|
||||||
|
|
||||||
if attributes.Flags&StatAttrSize != 0 {
|
if attributes.Flags&StatAttrSize != 0 {
|
||||||
|
|||||||
@@ -218,8 +218,12 @@ func (fs *GCSFs) Create(name string, flag int) (*os.File, *PipeWriter, func(), e
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
defer cancelFn()
|
defer cancelFn()
|
||||||
defer objectWriter.Close()
|
|
||||||
n, err := io.Copy(objectWriter, r)
|
n, err := io.Copy(objectWriter, r)
|
||||||
|
closeErr := objectWriter.Close()
|
||||||
|
if err == nil {
|
||||||
|
err = closeErr
|
||||||
|
}
|
||||||
r.CloseWithError(err) //nolint:errcheck
|
r.CloseWithError(err) //nolint:errcheck
|
||||||
p.Done(err)
|
p.Done(err)
|
||||||
fsLog(fs, logger.LevelDebug, "upload completed, path: %#v, readed bytes: %v, err: %v", name, n, err)
|
fsLog(fs, logger.LevelDebug, "upload completed, path: %#v, readed bytes: %v, err: %v", name, n, err)
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ type Fs interface {
|
|||||||
GetMimeType(name string) (string, error)
|
GetMimeType(name string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrVfsUnsupported defines the error for an unsupported VFS operation
|
||||||
var ErrVfsUnsupported = errors.New("Not supported")
|
var ErrVfsUnsupported = errors.New("Not supported")
|
||||||
|
|
||||||
// QuotaCheckResult defines the result for a quota check
|
// QuotaCheckResult defines the result for a quota check
|
||||||
|
|||||||
Reference in New Issue
Block a user