diff --git a/source/app/schema/marshables.py b/source/app/schema/marshables.py index 49a2bdaf2..95934e354 100644 --- a/source/app/schema/marshables.py +++ b/source/app/schema/marshables.py @@ -1113,17 +1113,22 @@ def ds_store_file(self, file_storage: FileStorage, location: Path, is_ioc: bool, if passwd is not None: try: - with tempfile.NamedTemporaryFile() as tmp: + with tempfile.NamedTemporaryFile(delete=False) as tmp: file_storage.save(tmp) - file_hash = file_sha256sum(tmp.name) - file_size = os.stat(tmp.name).st_size + file_storage.close() - file_path = location.as_posix() + '.zip' + fn = tmp - shutil.copyfile(tmp.name, Path(tmp.name).parent / file_hash) + file_hash = file_sha256sum(fn.name) + file_size = os.stat(fn.name).st_size - pyminizip.compress((Path(tmp.name).parent / file_hash).as_posix(), None, file_path, passwd, 0) - os.unlink(Path(tmp.name).parent / file_hash) + file_path = location.as_posix() + '.zip' + + shutil.copyfile(fn.name, Path(fn.name).parent / file_hash) + + pyminizip.compress((Path(fn.name).parent / file_hash).as_posix(), None, file_path, passwd, 0) + os.unlink(Path(tmp.name).parent / file_hash) + os.unlink(fn.name) except Exception as e: log.exception(e) @@ -1134,6 +1139,7 @@ def ds_store_file(self, file_storage: FileStorage, location: Path, is_ioc: bool, else: file_storage.save(location) + file_storage.close() file_path = location.as_posix() file_size = location.stat().st_size file_hash = file_sha256sum(file_path)