Write to a tempfile then move, so that if the
process dies mid-write it doesn't corrupt the store.
Also improve error messaging so that if a file does
get corrupted, the user has some hope of figuring
out which file is broken.
For background, see:
https://github.com/docker/for-win/issues/13180
https://github.com/docker/for-win/issues/12561
For a repro case, see:
https://github.com/nicks/contextstore-sandbox
Signed-off-by: Nick Santos <nick.santos@docker.com>
(cherry picked from commit c2487c2997)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>