git_handler.save_remote_refs: use an atomic temp file to write

This bug becomes obvious now that the code is structured like this.
This commit is contained in:
Siddharth Agarwal 2014-09-03 19:56:45 +02:00
parent 22561bae4b
commit 1a2929b055

View File

@ -207,10 +207,11 @@ class GitHandler(object):
self._remote_refs.update([(name, bin(sha)) for sha, name in td])
def save_remote_refs(self):
tf = open(self.repo.join(self.remote_refs_file), 'wb')
file = self.repo.opener(self.remote_refs_file, 'w+', atomictemp=True)
for tag, node in self.remote_refs.iteritems():
tf.write('%s %s\n' % (hex(node), tag))
tf.close()
file.write('%s %s\n' % (hex(node), tag))
# If this complains, atomictempfile no longer has close
file.close()
## END FILE LOAD AND SAVE METHODS