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:
Nicola Murino
2024-12-14 13:19:02 +01:00
parent 7703f57122
commit 599ee5a58f
3 changed files with 13 additions and 3 deletions

View File

@@ -793,7 +793,7 @@ func (c *BaseConnection) Rename(virtualSourcePath, virtualTargetPath string) err
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,
) error {
if virtualSourcePath == virtualTargetPath {
@@ -816,7 +816,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",

View File

@@ -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() {
@@ -348,7 +351,7 @@ func (*eventRulesContainer) checkFsEventMatch(conditions *dataprovider.EventCond
if len(conditions.Options.Protocols) > 0 && !slices.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

View File

@@ -105,6 +105,9 @@ func (fi *FileInfo) setMetadataFromPointerVal(value 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 len(val) > 0 {
return val