Make Hierarchy.write_metadata() an atomic operation
This commit is contained in:
parent
4361ad703a
commit
e58c6b7c27
@ -100,11 +100,18 @@ class Hierarchy:
|
||||
return pickle.load(mfile)
|
||||
|
||||
def write_metadata(self):
|
||||
"""Write this repository's metadata to its file."""
|
||||
"""Write this repository's metadata to its file.
|
||||
Note that this write operation is atomic to the caller.
|
||||
"""
|
||||
syslog.debug(f"Writing metadata to {self.metadata_path}")
|
||||
with self.metadata_path.open(mode=METADATA_WRITE) as mfile:
|
||||
|
||||
tmpfile = self.metadata_path.with_suffix('.tmp')
|
||||
|
||||
with tmpfile.open(mode=METADATA_WRITE) as mfile:
|
||||
pickle.dump(self._data, mfile)
|
||||
|
||||
tmpfile.rename(self.metadata_path)
|
||||
|
||||
|
||||
# ========== Functions ==========
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
x
Reference in New Issue
Block a user