compiler: truncate output files before writing

This commit is contained in:
Ayke van Laethem
2018-09-16 13:41:56 +02:00
parent 35fe24981f
commit a25e598463
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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
}