Files
zurg/internal/torrent/hooks.go
Ben Sarmiento 3df201cc20 Fixes
2023-12-02 20:37:40 +01:00

52 lines
1.0 KiB
Go

package torrent
import (
"fmt"
"os/exec"
"github.com/debridmediamanager/zurg/internal/config"
"go.uber.org/zap"
)
type ScriptExecutor struct {
Script string
Args []string
}
func (se *ScriptExecutor) Execute() error {
if se.Script == "" {
return nil
}
// Prepare the command
cmd := exec.Command("/bin/sh", "-c", se.Script)
cmd.Args = append(cmd.Args, se.Args...)
// Start the command and immediately return, not caring about its state
err := cmd.Start()
if err != nil {
return fmt.Errorf("error starting script: %v", err)
}
// Detach the process
go func() {
cmd.Wait()
}()
return nil
}
func OnLibraryUpdateHook(paths []string, config config.ConfigInterface, log *zap.SugaredLogger) {
executor := &ScriptExecutor{
Script: config.GetOnLibraryUpdate(),
Args: paths,
}
err := executor.Execute()
if err != nil {
log.Errorf("Failed to execute hook on_library_update: %v", err)
return
}
log.Infof("Successfully executed hook on_library_update")
// No need to log the output since we're not capturing it
}