From 1a894bc29018a0db5340ecccf33297a24c5fc141 Mon Sep 17 00:00:00 2001 From: Arkadiy Tetelman Date: Fri, 10 Apr 2026 23:57:36 -0700 Subject: [PATCH] Don't overwrite existing files --- cmd/protodump/main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/protodump/main.go b/cmd/protodump/main.go index 6595806..d79f98a 100644 --- a/cmd/protodump/main.go +++ b/cmd/protodump/main.go @@ -55,10 +55,17 @@ func writeFile(outputDir string, filename string, content []byte) (string, error } final := filepath.Join(base, rest, fileBase) - err = os.WriteFile(final, content, 0700) + + file, err := os.OpenFile(final, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0644) + if err != nil { + return "", fmt.Errorf("failed to open file %s: %v", final, err) + } + defer file.Close() + _, err = file.Write(content) if err != nil { return "", fmt.Errorf("failed to write file %s: %v", final, err) } + return final, nil }