Skip to content

Commit

Permalink
cmd/age: overwrite output file if existing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
FiloSottile committed Mar 10, 2021
1 parent 629b0db commit 801a7e8
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions cmd/age/age.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 801a7e8

Please sign in to comment.