Closed dalechyn closed 5 years ago
Hey. I am a little confused in what is going on with deferring files closing in internal/cp/copy.go.
internal/cp/copy.go
if err := out.Close(); err != nil { return err }
Isn't it an extra call to out.Close() since we have defer out.Close()?
out.Close()
defer out.Close()
If it is not, and It's just me missing something with Go defer call handling, why there is no error check for defer in.Close()?
defer
defer in.Close()
The deferred call is for avoiding resource leaks (we don’t care if it fails), the non-deferred call is for checking whether flushing the file to disk fails.
This is intentional :)
Hey. I am a little confused in what is going on with deferring files closing in
internal/cp/copy.go
.Isn't it an extra call to
out.Close()
since we havedefer out.Close()
?If it is not, and It's just me missing something with Go
defer
call handling, why there is no error check fordefer in.Close()
?