From a25e598463effbd83e8130219d7eebb16f44b6a1 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 16 Sep 2018 13:41:56 +0200 Subject: [PATCH] compiler: truncate output files before writing --- compiler.go | 2 +- main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler.go b/compiler.go index a9e37044..3aa70c3c 100644 --- a/compiler.go +++ b/compiler.go @@ -3180,7 +3180,7 @@ func (c *Compiler) EmitText(path string) error { // Write the data to the file specified by path. func (c *Compiler) writeFile(data []byte, path string) error { // Write output to file - f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0666) + f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666) if err != nil { return err } diff --git a/main.go b/main.go index ded05ac6..99e29414 100644 --- a/main.go +++ b/main.go @@ -114,7 +114,7 @@ func Build(pkgName, outpath, target string, printIR, dumpSSA bool) error { return err } defer inf.Close() - outf, err := os.OpenFile(outpath, os.O_RDWR|os.O_CREATE, 0777) + outf, err := os.OpenFile(outpath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777) if err != nil { return err }