mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-14 12:06:42 +08:00
when saving a snapshots file, copy it to a temporary place and then do a mv. This makes it easier to use this program in conjunction with an inotify-based service that will act on newly-created snapshost (doing a mv is atomic, whereas a create + copy is not)
This commit is contained in:
@@ -360,8 +360,11 @@ def make_snapshot(working_dir, snapshots_dir, private_key, block_number):
|
||||
if os.path.exists('snapshot.bsk'):
|
||||
os.unlink('snapshot.bsk')
|
||||
|
||||
# copy it in
|
||||
shutil.copy('snapshot.bsk.{}'.format(block_number), 'snapshot.bsk')
|
||||
# copy it in.
|
||||
# do in two steps, so we can watch the directory and be assured that when the move completes,
|
||||
# the file has been completely written.
|
||||
shutil.copy('snapshot.bsk.{}'.format(block_number), '.snapshot.bsk')
|
||||
shutil.move('.snapshot.bsk', 'snapshot.bsk')
|
||||
except Exception as e:
|
||||
log.exception(e)
|
||||
return {'error': 'Failed to copy {} to {}'.format('snapshot.bsk.{}'.format(block_number), 'snapshot.bsk')}
|
||||
|
||||
Reference in New Issue
Block a user