Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,20 +602,30 @@ func parseOutputs(specs []string, def output.Format) ([]outputTarget, error) {
return targets, nil
}

// checkOutputFiles refuses an -inconclusive, -stats or -sarif file that is
// also an -o file or another of them: the last one written would replace the
// others (#378).
// checkOutputFiles refuses two outputs that name the same file: the last one
// written would replace the others (#378, #395). -state is compared with every
// output so an interrupted run cannot lose its resume state. -diff is compared
// with the other non--o reports, but -o X -diff X is allowed (#297).
func checkOutputFiles(f cliFlags, outputs []outputTarget) error {
type named struct{ flag, path string }
var files []named
for _, t := range outputs {
files = append(files, named{"-o", t.path})
}
for _, n := range []named{{"-inconclusive", f.inconFile}, {"-stats", f.statsFile}, {"-sarif", f.sarifFile}} {
for _, n := range []named{
{"-state", f.stateFile},
{"-inconclusive", f.inconFile},
{"-stats", f.statsFile},
{"-sarif", f.sarifFile},
{"-diff", f.diff},
} {
if n.path == "" {
continue
}
for _, prev := range files {
if n.flag == "-diff" && prev.flag == "-o" {
continue
}
if samePath(prev.path, n.path) {
return fmt.Errorf("%s %s and %s %s name the same file; give each its own", prev.flag, prev.path, n.flag, n.path)
}
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/wordlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func TestOutputFilesSameFile(t *testing.T) {
"-o and -stats": {"-o", abs, "-stats", rel},
"-o and -sarif": {"-o", abs, "-sarif", abs},
"-stats and -inconclusive": {"-stats", abs, "-inconclusive", rel},
"-state and -o": {"-state", abs, "-o", "text:" + rel},
"-state and -stats": {"-state", abs, "-stats", rel},
"-state and -diff": {"-state", abs, "-diff", rel},
"-diff and -stats": {"-diff", abs, "-stats", rel},
}
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
cases["-o twice, another case"] = []string{"-o", abs, "-o", "jsonl:" + strings.ToUpper(abs)}
Expand Down
Loading