b := new(bytes.Buffer)
var w io.Writer = b
if logfile != "" {
- f, err := os.Create(logfile)
+ f, err := os.OpenFile(logfile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
return
}
func isCreateFlag(flag ast.Expr) bool {
foundCreate := false
foundTrunc := false
+ foundAppend := false
// OR'ing of flags: is O_CREATE on? + or | would be fine; we just look for os.O_CREATE
// and don't worry about the actual opeator.
p := flag.Pos()
if isPkgDot(lhs, "os", "O_TRUNC") {
foundTrunc = true
}
+ if isPkgDot(lhs, "os", "O_APPEND") {
+ foundAppend = true
+ }
if !isBinary {
break
}
flag = expr.X
}
- if foundCreate && !foundTrunc {
+ if !foundCreate {
+ return false
+ }
+ if foundAppend {
+ return false
+ }
+ if !foundTrunc {
warn(p, "rewrote os.Open with O_CREATE but not O_TRUNC to os.Create")
}
return foundCreate
os.Open(a, os.O_CREATE, 0666)
os.Open(a, os.O_CREATE|os.O_TRUNC, 0664)
os.Open(a, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
+ os.Open(a, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
_ = os.O_CREAT
}
`,
os.Create(a)
os.Create(a)
os.Create(a)
+ os.OpenFile(a, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
_ = os.O_CREATE
}
`,
if installedPkgs[pkg] {
return
}
- fout, err := os.Create(logfile)
+ fout, err := os.OpenFile(logfile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %s\n", argv0, err)
return
certOut.Close()
log.Print("written cert.pem\n")
- keyOut, err := os.OpenFile("key.pem", os.O_WRONLY|os.O_CREAT, 0600)
+ keyOut, err := os.OpenFile("key.pem", os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0600)
if err != nil {
log.Print("failed to open key.pem for writing:", err)
return