atomicfile
atomicfile copied to clipboard
Fix windows panic on os.Rename when target file exists
Try to delete it first, but only on windows since it isn't atomic at all.
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks!
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!
This means it's no longer atomic :( Looks like https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx is one way to make this atomic on windows. I don't have a windows machine handy, but I think we should attempt to build an atomic version of this before we give up and go the os.Remove route.
Yeah, I agree about it not being very good.. I should probably just have opened an issue instead..
Related golang issue planned for go1.5: https://github.com/golang/go/issues/8914
And here is an implementation: https://github.com/lvarvel/cacheddownloader/commit/505a1fdcc5af7823f20d7c87d9e4d1c833c59053'
I'm not really in a hurry getting this resolved right now.