Reenable output for hook script
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package torrent
|
package torrent
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
@@ -13,27 +14,22 @@ type ScriptExecutor struct {
|
|||||||
Args []string
|
Args []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (se *ScriptExecutor) Execute() error {
|
func (se *ScriptExecutor) Execute() (string, error) {
|
||||||
if se.Script == "" {
|
if se.Script == "" {
|
||||||
return nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the command
|
|
||||||
cmd := exec.Command("/bin/sh", "-c", se.Script)
|
cmd := exec.Command("/bin/sh", "-c", se.Script)
|
||||||
|
cmd.Args = append(cmd.Args, "zurg")
|
||||||
cmd.Args = append(cmd.Args, se.Args...)
|
cmd.Args = append(cmd.Args, se.Args...)
|
||||||
|
var out bytes.Buffer
|
||||||
// Start the command and immediately return, not caring about its state
|
var stderr bytes.Buffer
|
||||||
err := cmd.Start()
|
cmd.Stdout = &out
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error starting script: %v", err)
|
return "", fmt.Errorf("error executing script: %v; stderr: %s", err, stderr.String())
|
||||||
}
|
}
|
||||||
|
return out.String(), nil
|
||||||
// Detach the process
|
|
||||||
go func() {
|
|
||||||
cmd.Wait()
|
|
||||||
}()
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func OnLibraryUpdateHook(paths []string, config config.ConfigInterface, log *zap.SugaredLogger) {
|
func OnLibraryUpdateHook(paths []string, config config.ConfigInterface, log *zap.SugaredLogger) {
|
||||||
@@ -41,11 +37,12 @@ func OnLibraryUpdateHook(paths []string, config config.ConfigInterface, log *zap
|
|||||||
Script: config.GetOnLibraryUpdate(),
|
Script: config.GetOnLibraryUpdate(),
|
||||||
Args: paths,
|
Args: paths,
|
||||||
}
|
}
|
||||||
err := executor.Execute()
|
output, err := executor.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to execute hook on_library_update: %v", err)
|
log.Errorf("Failed to execute hook on_library_update: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Infof("Successfully executed hook on_library_update")
|
if output != "" {
|
||||||
// No need to log the output since we're not capturing it
|
log.Infof("Output of hook on_library_update:\n%s", output)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user