fix(hooks): check if hook exits on disk

Prevents it from just crashing and returning 500
to the client.
This commit is contained in:
Rio Kierkels 2016-09-15 12:24:42 +02:00
parent bea4d10ae6
commit e63f225520
No known key found for this signature in database
GPG Key ID: ECD8A8003C39F2D7
1 changed files with 11 additions and 3 deletions

View File

@ -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))