fix(hooks): check if hook exits on disk
Prevents it from just crashing and returning 500 to the client.
This commit is contained in:
parent
bea4d10ae6
commit
e63f225520
|
@ -70,10 +70,18 @@ func invokeHookSync(typ HookType, info tusd.FileInfo, captureOutput bool) ([]byt
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
name := string(typ)
|
// Build path to hook
|
||||||
stdout.Printf("Invoking %s hook…\n", name)
|
hook_path := Flags.HooksDir + "/" + string(typ)
|
||||||
|
|
||||||
cmd := exec.Command(Flags.HooksDir + "/" + name)
|
// Check if the hook actually exists and return early if it doesn't
|
||||||
|
if _, err := os.Stat(hook_path); os.IsNotExist(err) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute the hook
|
||||||
|
stdout.Printf("Invoking %s hook…\n", hook_path)
|
||||||
|
|
||||||
|
cmd := exec.Command(hook_path)
|
||||||
env := os.Environ()
|
env := os.Environ()
|
||||||
env = append(env, "TUS_ID="+info.ID)
|
env = append(env, "TUS_ID="+info.ID)
|
||||||
env = append(env, "TUS_SIZE="+strconv.FormatInt(info.Size, 10))
|
env = append(env, "TUS_SIZE="+strconv.FormatInt(info.Size, 10))
|
||||||
|
|
Loading…
Reference in New Issue