- f = open(fn + '.tmp', 'w')
- count = 0
- progress('Receiving index from server: %d/%d\r' % (count, n))
- for b in chunkyreader(self.conn, n):
- f.write(b)
- count += len(b)
- qprogress('Receiving index from server: %d/%d\r' % (count, n))
- progress('Receiving index from server: %d/%d, done.\n' % (count, n))
- self.check_ok()
- f.close()
- os.rename(fn + '.tmp', fn)
+ with atomically_replaced_file(fn, 'w') as f:
+ count = 0
+ progress('Receiving index from server: %d/%d\r' % (count, n))
+ for b in chunkyreader(self.conn, n):
+ f.write(b)
+ count += len(b)
+ qprogress('Receiving index from server: %d/%d\r' % (count, n))
+ progress('Receiving index from server: %d/%d, done.\n' % (count, n))
+ self.check_ok()