Commit b07b373b authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼

Remove temporary files

parent 6fc26a35
...@@ -181,7 +181,6 @@ class Signature: ...@@ -181,7 +181,6 @@ class Signature:
""" """
Download a tar of the repository from cache, and untar it. Download a tar of the repository from cache, and untar it.
""" """
info, sha256path = tempfile.mkstemp()
shacache = NetworkCache(self.config.slapos_configuration) shacache = NetworkCache(self.config.slapos_configuration)
if shacache.signature_certificate_list is None: if shacache.signature_certificate_list is None:
...@@ -193,11 +192,12 @@ class Signature: ...@@ -193,11 +192,12 @@ class Signature:
if download_metadata_dict: if download_metadata_dict:
self.log('File downloaded in %s', path) self.log('File downloaded in %s', path)
current_sha256 = self.get_file_hash(path) current_sha256 = self.get_file_hash(path)
with tempfile.NamedTemporaryFile() as f_256:
sha256path = f_256.name
if shacache.download(path=sha256path, required_key_list=['timestamp'], if shacache.download(path=sha256path, required_key_list=['timestamp'],
strategy=strategy, is_sha256file=True): strategy=strategy, is_sha256file=True):
self.log('sha 256 downloaded in %s', sha256path) self.log('sha 256 downloaded in %s', sha256path)
with open(sha256path, 'rb') as f: expected_sha256 = f_256.read()
expected_sha256 = f.read()
if current_sha256 == expected_sha256: if current_sha256 == expected_sha256:
return True return True
...@@ -209,9 +209,15 @@ class Signature: ...@@ -209,9 +209,15 @@ class Signature:
Get status information and return its path Get status information and return its path
""" """
info, path = tempfile.mkstemp() info, path = tempfile.mkstemp()
if not self._download(path) == False: if self._download(path):
try:
shutil.move(path, self.config.destination) shutil.move(path, self.config.destination)
except Exception as e:
self.log(e)
self.log('Fail to move %s to %s, maybe permission problem?', path, self.config.destination)
os.remove(path)
else: else:
os.remove(path)
raise ValueError("No result from shacache") raise ValueError("No result from shacache")
def _upload(self, path): def _upload(self, path):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment