You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/12/02 21:54:15 UTC
incubator-mynewt-newt git commit: newt - Add missing O_TRUNC flags.
Repository: incubator-mynewt-newt
Updated Branches:
refs/heads/develop fbfdff657 -> 51906cf25
newt - Add missing O_TRUNC flags.
When newt overwrites an existing file, it needs to specify the
os.O_TRUNC flag to os.Open(). Otherwise, the file gets overwritten in
place and stale data might remain at the end. This was causing
confusing issues with invalid dependency files (.d).
This issue is new because we no longer invoke the shell for external
commands. Previously, we truncated files by redirecting shell output.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/51906cf2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/51906cf2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/51906cf2
Branch: refs/heads/develop
Commit: 51906cf25e21bbaade78926994187571791ab011
Parents: fbfdff6
Author: Christopher Collins <cc...@apache.org>
Authored: Fri Dec 2 13:52:30 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Fri Dec 2 13:52:30 2016 -0800
----------------------------------------------------------------------
newt/toolchain/compiler.go | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/51906cf2/newt/toolchain/compiler.go
----------------------------------------------------------------------
diff --git a/newt/toolchain/compiler.go b/newt/toolchain/compiler.go
index e885ef4..71a99dd 100644
--- a/newt/toolchain/compiler.go
+++ b/newt/toolchain/compiler.go
@@ -422,7 +422,7 @@ func (c *Compiler) GenDepsForFile(file string) error {
}
// Write the compiler output to a dependency file.
- f, err := os.OpenFile(depFile, os.O_CREATE|os.O_WRONLY, 0666)
+ f, err := os.OpenFile(depFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
if err != nil {
return util.ChildNewtError(err)
}
@@ -912,7 +912,8 @@ func (c *Compiler) generateExtras(elfFilename string,
if options["listFile"] {
listFile := elfFilename + ".lst"
- f, err := os.OpenFile(listFile, os.O_CREATE|os.O_WRONLY, 0666)
+ f, err := os.OpenFile(listFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC,
+ 0666)
if err != nil {
return util.NewNewtError(err.Error())
}
@@ -1085,7 +1086,8 @@ func createSplitArchiveLinkerFile(archiveFile string,
ar_script_name := linkerScriptFileName(archiveFile)
// open the file and write out the script
- f, err := os.OpenFile(ar_script_name, os.O_CREATE|os.O_WRONLY, 0666)
+ f, err := os.OpenFile(ar_script_name, os.O_CREATE|os.O_WRONLY|os.O_TRUNC,
+ 0666)
if err != nil {
return util.NewNewtError(err.Error())
}