Skip to content

Commit

Permalink
Fixes added as expected for #1526
Browse files Browse the repository at this point in the history
Signed-off-by: Suvaditya Mukherjee <suvadityamuk@gmail.com>
  • Loading branch information
suvadityamuk committed Aug 25, 2021
1 parent b078fee commit 118ceca
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions tuf/ngclient/updater.py
Expand Up @@ -293,22 +293,20 @@ def _load_local_metadata(self, rolename: str) -> bytes:
return f.read()

def _persist_metadata(self, rolename: str, data: bytes):
"""Saving metadata in one move operation. To ensure there is no chance for loss of data during writing,
"""Saving metadata in one move operation. To ensure there is
no chance for loss of data during writing,
the data is first written to temp file followed by
an atomic move operation to the correct file location
to make sure that if data writing process is halted
or interrupted, the original data is not lost.
"""

original_file_touch = open(f"{rolename}.json", "a+")

original_file_touch.close()
file_name = f"{rolename}.json"
file_out = tempfile.NamedTemporaryFile(
dir=os.path.dirname(file_name), delete=False
)
file_out.write(data)
os.replace(file_out.name, file_name)
with tempfile.NamedTemporaryFile(
dir=self._dir, delete=False
) as temp_file:
temp_file.write(data)
os.replace(temp_file.name, file_name)

def _load_root(self) -> None:
"""Load remote root metadata.
Expand Down

0 comments on commit 118ceca

Please sign in to comment.