[PATCH] D19838: [LLVM-AR] Fixed bug where temporary file would be left behind every time an archive was updated

Cameron via llvm-commits llvm-commits at lists.llvm.org
Fri May 6 07:25:08 PDT 2016


cameron314 added a comment.

I thought this would be an issue on POSIX as well, but after reading the documentation and testing it on a Linux machine it actually isn't -- POSIX allows a file to be renamed to a file that is currently open. This seems really unsafe to me since whoever has the destination file already open is getting the contents on disk changed out from under them (unless my understanding is off) which could cause all sorts of nasty corruption issues if there's a non-empty read or write buffer (or unflushed mapped memory) on that filehandle. (On Windows, a file that is in use can generally be renamed but not deleted, and the open handles keep referring to the same file regardless of its name -- which is why `ReplaceFile` in this case renames the destination file to let it hang around for whoever has it open.)

I'll expand the comment, good call!

I really don't know how to test this nicely. It depends on whether `shouldUseMmap` returns true in MemoryBuffer.cpp. The temporary files seem to be of the form "destarcname.a~RFnnnnxxxx.TMP", but this is a Win32 implementation detail and is not documented on MSDN, so is probably subject to change.


http://reviews.llvm.org/D19838





More information about the llvm-commits mailing list