configure.py: atomically overwrite build.ninja
configure.py: atomically overwrite build.ninja

configure.py currently takes some time to write build.ninja. If the user
interrupts (e.g., control-C) configure.py, it can leave behind a partial
or even empty build.ninja file. This is most frustrating when the user
didn't explicitly run "configure.py", but rather just ran "ninja" and
ninja decided to run configure.py, and after interrupting it the user
cannot run "ninja" again because build.ninja is gone. Another result of
losing build.ninja is that the user now needs to remember which parameters
to run "configure.py", because the old ones stored in build.ninja were lost.

The solution in this patch is simple: We write the new build.ninja contents
into a temporary file, not directly into build.ninja. Then, only when the
entire file has been succesfully written, do we rename the temporary file
to its intended name - build.ninja.

Fixes #4706

Signed-off-by: Nadav Har'El <625169824b719df98706d88646d0aae6f368ae4d@scylladb.com>
Reviewed-by: Botond Dénes <a584fa4d75a0a85d721f44fb6e06315a2853b0b6@scylladb.com>
Message-Id: <20190715122129.16033-1-625169824b719df98706d88646d0aae6f368ae4d@scylladb.com>

scylladb/scylla,scylladb/scylla,avikivity/scylla,avikivity/scylla,scylladb/scylla,scylladb/scylla,avikivity/scylla