mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-06 14:20:55 +03:00
EventManager: check file size for more events
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -792,7 +792,7 @@ func (c *BaseConnection) Rename(virtualSourcePath, virtualTargetPath string) err
|
||||
return c.renameInternal(virtualSourcePath, virtualTargetPath, false)
|
||||
}
|
||||
|
||||
func (c *BaseConnection) renameInternal(virtualSourcePath, virtualTargetPath string, checkParentDestination bool) error {
|
||||
func (c *BaseConnection) renameInternal(virtualSourcePath, virtualTargetPath string, checkParentDestination bool) error { //nolint:gocyclo
|
||||
if virtualSourcePath == virtualTargetPath {
|
||||
return fmt.Errorf("the rename source and target cannot be the same: %w", c.GetOpUnsupportedError())
|
||||
}
|
||||
@@ -813,7 +813,11 @@ func (c *BaseConnection) renameInternal(virtualSourcePath, virtualTargetPath str
|
||||
return c.GetPermissionDeniedError()
|
||||
}
|
||||
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
|
||||
if dstInfo.IsDir() {
|
||||
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 eventRulesContainer
|
||||
multipartQuoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"")
|
||||
fsEventsWithSize = []string{operationPreDelete, OperationPreUpload, operationDelete,
|
||||
operationCopy, operationDownload, operationFirstUpload, operationFirstDownload,
|
||||
operationUpload}
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -347,7 +350,7 @@ func (*eventRulesContainer) checkFsEventMatch(conditions *dataprovider.EventCond
|
||||
if len(conditions.Options.Protocols) > 0 && !util.Contains(conditions.Options.Protocols, params.Protocol) {
|
||||
return false
|
||||
}
|
||||
if params.Event == operationUpload || params.Event == operationDownload {
|
||||
if slices.Contains(fsEventsWithSize, params.Event) {
|
||||
if conditions.Options.MinFileSize > 0 {
|
||||
if params.FileSize < conditions.Options.MinFileSize {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user