router_rebuild_store() uses a needless tmp file
In router_rebuild_store(), we use write_chunks_to_file() to build cached_descriptors.tmp, and if that is successful, we rename cached_descriptors.tmp to cached_descriptors.
But write_chunks_to_file() already uses a tmpfile to make sure that it doesn't trash the file it's writing to, so we wind up with the following situation:
router_rebuild_store() calls write_chunks_to_file(), which does: open("cached_descriptors.tmp.tmp") write rename("cached_descriptors.tmp.tmp","cached_descriptors.tmp") munmap("cached_descriptors") rename("cached_descriptors.tmp", "cached_descriptors") mmap("cached_descriptors")
One imaginable fix would be to have router_rebuild_store() tell write_chunks_to_file to write into cached_descriptors directly, so that it would write into c-d.tmp then rename it to c-d. That won't work so easily, though: on Windows, you're not allowed to replace a mapped file while it's still mapped.
A better fix would be to add a flag to write_chunks_to_file() so that it takes a flag that decides whether to use a tmpfile or not.
Found by grarpamp on or-talk: http://archives.seul.org/or/talk/Mar-2010/msg00173.html
This bug isn't actually hurting anything by doing an extra rename(), so it isn't urgent to fix.