diff --git a/cmd/utils.go b/cmd/utils.go index 78f48d1307..a8ab19361a 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -194,7 +194,7 @@ func convertCmdStrToCmdArray(cmd string) []string { var cmdArray []string trimmedCmdStr := strings.TrimSpace(cmd) if trimmedCmdStr != "" { - cmdArray = strings.Split(trimmedCmdStr, " ") + cmdArray = strings.Split(trimmedCmdStr, ",") } return cmdArray } diff --git a/http/tus_handlers.go b/http/tus_handlers.go index 7a3254ae72..773b3d0d88 100644 --- a/http/tus_handlers.go +++ b/http/tus_handlers.go @@ -131,6 +131,13 @@ func tusPatchHandler() handleFunc { ) } + if uploadOffset == 0 { + err = d.RunBeforeHook("upload", r.URL.Path, "", d.user) + if err != nil { + return errToStatus(err), err + } + } + openFile, err := d.user.Fs.OpenFile(r.URL.Path, os.O_WRONLY|os.O_APPEND, files.PermFile) if err != nil { return http.StatusInternalServerError, fmt.Errorf("could not open file: %w", err) @@ -150,6 +157,13 @@ func tusPatchHandler() handleFunc { w.Header().Set("Upload-Offset", strconv.FormatInt(uploadOffset+bytesWritten, 10)) + if bytesWritten < int64(d.Settings.Tus.ChunkSize) { + err = d.RunAfterHook("upload", r.URL.Path, "", d.user) + if err != nil { + return errToStatus(err), err + } + } + return http.StatusNoContent, nil }) } diff --git a/runner/parser.go b/runner/parser.go index 6fd64a4b64..8161a6e543 100644 --- a/runner/parser.go +++ b/runner/parser.go @@ -8,7 +8,7 @@ import ( // ParseCommand parses the command taking in account if the current // instance uses a shell to run the commands or just calls the binary -// directyly. +// directly. func ParseCommand(s *settings.Settings, raw string) ([]string, error) { var command []string @@ -26,7 +26,19 @@ func ParseCommand(s *settings.Settings, raw string) ([]string, error) { command = append(command, cmd) command = append(command, args...) } else { - command = append(s.Shell, raw) //nolint:gocritic + cmd, args, err := SplitCommandAndArgs(s.Shell[0]) + if err != nil { + return nil, err + } + + _, err = exec.LookPath(cmd) + if err != nil { + return nil, err + } + + command = append(command, cmd) + command = append(command, args...) + command = append(command, raw) } return command, nil diff --git a/runner/runner.go b/runner/runner.go index 2dbafa5cd1..829e591020 100644 --- a/runner/runner.go +++ b/runner/runner.go @@ -17,6 +17,39 @@ type Runner struct { *settings.Settings } +// RunBeforeHook and RunAfterHook trigger the command runner at their respective times. +func (r *Runner) RunBeforeHook(evt, path, dst string, user *users.User) error { + path = user.FullPath(path) + dst = user.FullPath(dst) + if r.Enabled { + if val, ok := r.Commands["before_"+evt]; ok { + for _, command := range val { + err := r.exec(command, "before_"+evt, path, dst, user) + if err != nil { + return err + } + } + } + } + return nil +} + +func (r *Runner) RunAfterHook(evt, path, dst string, user *users.User) error { + path = user.FullPath(path) + dst = user.FullPath(dst) + if r.Enabled { + if val, ok := r.Commands["after_"+evt]; ok { + for _, command := range val { + err := r.exec(command, "after_"+evt, path, dst, user) + if err != nil { + return err + } + } + } + } + return nil +} + // RunHook runs the hooks for the before and after event. func (r *Runner) RunHook(fn func() error, evt, path, dst string, user *users.User) error { path = user.FullPath(path)