Skip to content

Commit 42f349a

Browse files
author
zgy
authored
Include -state and -diff in output-file clash check (#428)
checkOutputFiles skipped -state, so -stats or -o could overwrite the resume state after it was saved and reported. Compare -state with every output and -diff with the other non--o reports, keeping -o X -diff X legal (#395).
1 parent fee3073 commit 42f349a

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎internal/cli/cli.go‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,20 +602,30 @@ func parseOutputs(specs []string, def output.Format) ([]outputTarget, error) {
602602
return targets, nil
603603
}
604604

605-
// checkOutputFiles refuses an -inconclusive, -stats or -sarif file that is
606-
// also an -o file or another of them: the last one written would replace the
607-
// others (#378).
605+
// checkOutputFiles refuses two outputs that name the same file: the last one
606+
// written would replace the others (#378, #395). -state is compared with every
607+
// output so an interrupted run cannot lose its resume state. -diff is compared
608+
// with the other non--o reports, but -o X -diff X is allowed (#297).
608609
func checkOutputFiles(f cliFlags, outputs []outputTarget) error {
609610
type named struct{ flag, path string }
610611
var files []named
611612
for _, t := range outputs {
612613
files = append(files, named{"-o", t.path})
613614
}
614-
for _, n := range []named{{"-inconclusive", f.inconFile}, {"-stats", f.statsFile}, {"-sarif", f.sarifFile}} {
615+
for _, n := range []named{
616+
{"-state", f.stateFile},
617+
{"-inconclusive", f.inconFile},
618+
{"-stats", f.statsFile},
619+
{"-sarif", f.sarifFile},
620+
{"-diff", f.diff},
621+
} {
615622
if n.path == "" {
616623
continue
617624
}
618625
for _, prev := range files {
626+
if n.flag == "-diff" && prev.flag == "-o" {
627+
continue
628+
}
619629
if samePath(prev.path, n.path) {
620630
return fmt.Errorf("%s %s and %s %s name the same file; give each its own", prev.flag, prev.path, n.flag, n.path)
621631
}

‎internal/cli/wordlist_test.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ func TestOutputFilesSameFile(t *testing.T) {
113113
"-o and -stats": {"-o", abs, "-stats", rel},
114114
"-o and -sarif": {"-o", abs, "-sarif", abs},
115115
"-stats and -inconclusive": {"-stats", abs, "-inconclusive", rel},
116+
"-state and -o": {"-state", abs, "-o", "text:" + rel},
117+
"-state and -stats": {"-state", abs, "-stats", rel},
118+
"-state and -diff": {"-state", abs, "-diff", rel},
119+
"-diff and -stats": {"-diff", abs, "-stats", rel},
116120
}
117121
if runtime.GOOS == "windows" || runtime.GOOS == "darwin" {
118122
cases["-o twice, another case"] = []string{"-o", abs, "-o", "jsonl:" + strings.ToUpper(abs)}

0 commit comments

Comments
 (0)