Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make fileCopy more robust #11

Merged
merged 1 commit into from Aug 2, 2019
Merged

make fileCopy more robust #11

merged 1 commit into from Aug 2, 2019

Conversation

@kjk
Copy link
Contributor

kjk commented Aug 2, 2019

It's unlikely to happen, but Close() on a file being written to can fail due to unflushed os buffers. Close might fail even though io.Copy said it wrote all the data to the destination.

Does not apply to files being read from so no need to check error from source.Close()

@yevgenypats
Copy link
Collaborator

yevgenypats commented Aug 2, 2019

Interesting. Wasn't aware of that in Go. Can you link to some blog/ data about this?

@kjk
Copy link
Contributor Author

kjk commented Aug 2, 2019

It's not really a Go thing but an operating system thing. On the lowest level, a close syscall might fail which will propagate to file.Close().

https://www.joeshaw.org/dont-defer-close-on-writable-files/
https://www.reddit.com/r/golang/comments/3735so/do_we_have_to_check_for_errors_when_we_call_close/

https://linux.die.net/man/2/close:

Not checking the return value of close() is a common but nevertheless serious programming error.

@yevgenypats
Copy link
Collaborator

yevgenypats commented Aug 2, 2019

cool.

@yevgenypats yevgenypats merged commit ca5e96b into fuzzitdev:master Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.