mirror of
https://github.com/FiloSottile/age.git
synced 2026-04-20 19:10:29 +00:00
cmd/age: overwrite output file if existing
Not really the safest UX, but age is a UNIX tool, and this is what all UNIX tools do, so adopt the principle of least surprise.
This commit is contained in:
committed by
Filippo Valsorda
parent
629b0dbbc9
commit
801a7e8b33
@@ -169,9 +169,6 @@ func main() {
|
||||
stdinInUse = true
|
||||
}
|
||||
if name := outFlag; name != "" && name != "-" {
|
||||
if _, err := os.Stat(name); err == nil {
|
||||
logFatalf("Error: output file %q exists", name)
|
||||
}
|
||||
f := newLazyOpener(name)
|
||||
defer f.Close()
|
||||
out = f
|
||||
@@ -337,7 +334,7 @@ func newLazyOpener(name string) io.WriteCloser {
|
||||
|
||||
func (l *lazyOpener) Write(p []byte) (n int, err error) {
|
||||
if l.f == nil && l.err == nil {
|
||||
l.f, l.err = os.OpenFile(l.name, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0666)
|
||||
l.f, l.err = os.Create(l.name)
|
||||
}
|
||||
if l.err != nil {
|
||||
return 0, l.err
|
||||
|
||||
Reference in New Issue
Block a user