Skip to content

Commit

Permalink
EventManager: always close the connection filesystem
Browse files Browse the repository at this point in the history
closing the user filesystem is not enough here

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
  • Loading branch information
drakkan committed Nov 20, 2024
1 parent ee6049b commit 4470cc3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions internal/common/eventmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,7 @@ func getHTTPRuleActionBody(c *dataprovider.EventActionHTTPConfig, replacer *stri
go func() {
defer w.Close()
defer user.CloseFs() //nolint:errcheck
defer conn.CloseFS() //nolint:errcheck

for _, part := range c.Parts {
h := make(textproto.MIMEHeader)
Expand Down Expand Up @@ -1591,6 +1592,8 @@ func executeEmailRuleAction(c dataprovider.EventActionEmailConfig, params *Event
return fmt.Errorf("error getting email attachments, unable to check root fs for user %q: %w", user.Username, err)
}
conn := NewBaseConnection(connectionID, protocolEventAction, "", "", user)
defer conn.CloseFS() //nolint:errcheck

res, err := getMailAttachments(conn, fileAttachments, replacer)
if err != nil {
return err
Expand Down Expand Up @@ -1652,6 +1655,8 @@ func executeDeleteFsActionForUser(deletes []string, replacer *strings.Replacer,
return fmt.Errorf("delete error, unable to check root fs for user %q: %w", user.Username, err)
}
conn := NewBaseConnection(connectionID, protocolEventAction, "", "", user)
defer conn.CloseFS() //nolint:errcheck

for _, item := range replacePathsPlaceholders(deletes, replacer) {
info, err := conn.DoStat(item, 0, false)
if err != nil {
Expand Down Expand Up @@ -1720,6 +1725,8 @@ func executeMkDirsFsActionForUser(dirs []string, replacer *strings.Replacer, use
return fmt.Errorf("mkdir error, unable to check root fs for user %q: %w", user.Username, err)
}
conn := NewBaseConnection(connectionID, protocolEventAction, "", "", user)
defer conn.CloseFS() //nolint:errcheck

for _, item := range replacePathsPlaceholders(dirs, replacer) {
if err = conn.CheckParentDirs(path.Dir(item)); err != nil {
return fmt.Errorf("unable to check parent dirs for %q, user %q: %w", item, user.Username, err)
Expand Down Expand Up @@ -1779,6 +1786,8 @@ func executeRenameFsActionForUser(renames []dataprovider.RenameConfig, replacer
return fmt.Errorf("rename error, unable to check root fs for user %q: %w", user.Username, err)
}
conn := NewBaseConnection(connectionID, protocolEventAction, "", "", user)
defer conn.CloseFS() //nolint:errcheck

for _, item := range renames {
source := util.CleanPath(replaceWithReplacer(item.Key, replacer))
target := util.CleanPath(replaceWithReplacer(item.Value, replacer))
Expand Down Expand Up @@ -1808,6 +1817,8 @@ func executeCopyFsActionForUser(keyVals []dataprovider.KeyValue, replacer *strin
return fmt.Errorf("copy error, unable to check root fs for user %q: %w", user.Username, err)
}
conn := NewBaseConnection(connectionID, protocolEventAction, "", "", user)
defer conn.CloseFS() //nolint:errcheck

for _, item := range keyVals {
source := util.CleanPath(replaceWithReplacer(item.Key, replacer))
target := util.CleanPath(replaceWithReplacer(item.Value, replacer))
Expand Down Expand Up @@ -1839,6 +1850,8 @@ func executeExistFsActionForUser(exist []string, replacer *strings.Replacer,
return fmt.Errorf("existence check error, unable to check root fs for user %q: %w", user.Username, err)
}
conn := NewBaseConnection(connectionID, protocolEventAction, "", "", user)
defer conn.CloseFS() //nolint:errcheck

for _, item := range replacePathsPlaceholders(exist, replacer) {
if _, err = conn.DoStat(item, 0, false); err != nil {
return fmt.Errorf("error checking existence for path %q, user %q: %w", item, user.Username, err)
Expand Down Expand Up @@ -1997,6 +2010,8 @@ func executeCompressFsActionForUser(c dataprovider.EventActionFsCompress, replac
return fmt.Errorf("compress error, unable to check root fs for user %q: %w", user.Username, err)
}
conn := NewBaseConnection(connectionID, protocolEventAction, "", "", user)
defer conn.CloseFS() //nolint:errcheck

name := util.CleanPath(replaceWithReplacer(c.Name, replacer))
conn.CheckParentDirs(path.Dir(name)) //nolint:errcheck
paths := make([]string, 0, len(c.Paths))
Expand Down
1 change: 1 addition & 0 deletions internal/httpd/api_shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ func validateBrowsableShare(share dataprovider.Share, connection *Connection) er
basePath := share.Paths[0]
info, err := connection.Stat(basePath, 0)
if err != nil {
connection.CloseFS() //nolint:errcheck
return util.NewI18nError(
fmt.Errorf("unable to check the share directory: %w", err),
util.I18nErrorShareInvalidPath,
Expand Down

0 comments on commit 4470cc3

Please sign in to comment.