Skip to content

Commit 0ee2224

Browse files
aledbfclaude
andcommitted
taskgate: read asks what the path is before reading it
The check after a failed read let `&&` become `||` unnoticed: a file that exists but cannot be read would have been taken for one holding nothing. Asking first whether the path is gone or a directory, then reading, leaves every other failure to the read's own error, and each edit mutate makes to the condition breaks a test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent f33a805 commit 0ee2224

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎internal/taskgate/taskgate.go‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,15 @@ func Check(root string, limits Limits) ([]Finding, error) {
102102
return append(findings, found...), nil
103103
}
104104

105-
// read is rel's bytes, or none for a file git lists that is gone - deleted, not yet staged - or
106-
// that is a directory - a submodule, which git lists by its path - neither of which holds shell.
105+
// read is rel's bytes, or none for a path git lists that holds no shell: a file that is gone -
106+
// deleted, not yet staged - or a directory - a submodule, which git lists by its path.
107107
func read(root, rel string) ([]byte, error) {
108-
raw, err := os.ReadFile(filepath.Join(root, rel))
108+
p := filepath.Join(root, rel)
109+
if fi, err := os.Stat(p); os.IsNotExist(err) || err == nil && fi.IsDir() {
110+
return nil, nil
111+
}
112+
raw, err := os.ReadFile(p)
109113
if err != nil {
110-
if fi, serr := os.Stat(filepath.Join(root, rel)); os.IsNotExist(err) || serr == nil && fi.IsDir() {
111-
return nil, nil
112-
}
113114
return nil, fmt.Errorf("taskgate: %w", err)
114115
}
115116
return raw, nil

0 commit comments

Comments
 (0)