mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
Added O_TRUNC flag to file open and cleaned up code
This commit is contained in:
parent
fb889216ed
commit
66ed44061c
1 changed files with 5 additions and 8 deletions
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
@ -199,18 +198,16 @@ func dumpConfig(ctx *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dump := os.Stdout
|
||||||
if ctx.NArg() > 0 {
|
if ctx.NArg() > 0 {
|
||||||
f, err := os.OpenFile(ctx.Args().Get(0), os.O_RDWR|os.O_CREATE, 0644)
|
dump, err = os.OpenFile(ctx.Args().Get(0), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer dump.Close()
|
||||||
f.WriteString(comment)
|
|
||||||
f.Write(out)
|
|
||||||
} else {
|
|
||||||
io.WriteString(os.Stdout, comment)
|
|
||||||
os.Stdout.Write(out)
|
|
||||||
}
|
}
|
||||||
|
dump.WriteString(comment)
|
||||||
|
dump.Write(out)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue