mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-06 22:30:56 +03:00
EventManager: check file size for more events
Also add some defensive code Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -793,7 +793,7 @@ func (c *BaseConnection) Rename(virtualSourcePath, virtualTargetPath string) err
|
|||||||
return c.renameInternal(virtualSourcePath, virtualTargetPath, false, vfs.CheckParentDir)
|
return c.renameInternal(virtualSourcePath, virtualTargetPath, false, vfs.CheckParentDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *BaseConnection) renameInternal(virtualSourcePath, virtualTargetPath string,
|
func (c *BaseConnection) renameInternal(virtualSourcePath, virtualTargetPath string, //nolint:gocyclo
|
||||||
checkParentDestination bool, checks int,
|
checkParentDestination bool, checks int,
|
||||||
) error {
|
) error {
|
||||||
if virtualSourcePath == virtualTargetPath {
|
if virtualSourcePath == virtualTargetPath {
|
||||||
@@ -816,7 +816,11 @@ func (c *BaseConnection) renameInternal(virtualSourcePath, virtualTargetPath str
|
|||||||
return c.GetPermissionDeniedError()
|
return c.GetPermissionDeniedError()
|
||||||
}
|
}
|
||||||
initialSize := int64(-1)
|
initialSize := int64(-1)
|
||||||
if dstInfo, err := fsDst.Lstat(fsTargetPath); err == nil {
|
dstInfo, err := fsDst.Lstat(fsTargetPath)
|
||||||
|
if err != nil && !fsDst.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
checkParentDestination = false
|
checkParentDestination = false
|
||||||
if dstInfo.IsDir() {
|
if dstInfo.IsDir() {
|
||||||
c.Log(logger.LevelWarn, "attempted to rename %q overwriting an existing directory %q",
|
c.Log(logger.LevelWarn, "attempted to rename %q overwriting an existing directory %q",
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ var (
|
|||||||
// eventManager handle the supported event rules actions
|
// eventManager handle the supported event rules actions
|
||||||
eventManager eventRulesContainer
|
eventManager eventRulesContainer
|
||||||
multipartQuoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"")
|
multipartQuoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"")
|
||||||
|
fsEventsWithSize = []string{operationPreDelete, OperationPreUpload, operationDelete,
|
||||||
|
operationCopy, operationDownload, operationFirstUpload, operationFirstDownload,
|
||||||
|
operationUpload}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -348,7 +351,7 @@ func (*eventRulesContainer) checkFsEventMatch(conditions *dataprovider.EventCond
|
|||||||
if len(conditions.Options.Protocols) > 0 && !slices.Contains(conditions.Options.Protocols, params.Protocol) {
|
if len(conditions.Options.Protocols) > 0 && !slices.Contains(conditions.Options.Protocols, params.Protocol) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if params.Event == operationUpload || params.Event == operationDownload {
|
if slices.Contains(fsEventsWithSize, params.Event) {
|
||||||
if conditions.Options.MinFileSize > 0 {
|
if conditions.Options.MinFileSize > 0 {
|
||||||
if params.FileSize < conditions.Options.MinFileSize {
|
if params.FileSize < conditions.Options.MinFileSize {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -105,6 +105,9 @@ func (fi *FileInfo) setMetadataFromPointerVal(value map[string]*string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getMetadata(fi os.FileInfo) map[string]string {
|
func getMetadata(fi os.FileInfo) map[string]string {
|
||||||
|
if fi.Sys() == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if val, ok := fi.Sys().(map[string]string); ok {
|
if val, ok := fi.Sys().(map[string]string); ok {
|
||||||
if len(val) > 0 {
|
if len(val) > 0 {
|
||||||
return val
|
return val
|
||||||
|
|||||||
Reference in New Issue
Block a user