|
1 | 1 | import hashlib |
2 | 2 | import logging |
3 | | -import os |
4 | 3 | import pkginfo |
5 | 4 | import re |
6 | 5 | import shutil |
@@ -273,40 +272,32 @@ def artifact_to_metadata_artifact( |
273 | 272 |
|
274 | 273 | temp_wheel_path = None |
275 | 274 | temp_metadata_path = None |
| 275 | + |
| 276 | + with tempfile.NamedTemporaryFile("wb", dir=tmp_dir, suffix=filename, delete=False) as temp_file: |
| 277 | + temp_wheel_path = temp_file.name |
| 278 | + artifact.file.seek(0) |
| 279 | + shutil.copyfileobj(artifact.file, temp_file) |
| 280 | + temp_file.flush() |
| 281 | + |
| 282 | + metadata_content = extract_wheel_metadata(temp_wheel_path) |
| 283 | + if not metadata_content: |
| 284 | + return None |
| 285 | + |
| 286 | + with tempfile.NamedTemporaryFile( |
| 287 | + "wb", dir=tmp_dir, suffix=".metadata", delete=False |
| 288 | + ) as temp_md: |
| 289 | + temp_metadata_path = temp_md.name |
| 290 | + temp_md.write(metadata_content) |
| 291 | + temp_md.flush() |
| 292 | + |
| 293 | + metadata_artifact = Artifact.init_and_validate(temp_metadata_path) |
276 | 294 | try: |
277 | | - with tempfile.NamedTemporaryFile( |
278 | | - "wb", dir=tmp_dir, suffix=filename, delete=False |
279 | | - ) as temp_file: |
280 | | - temp_wheel_path = temp_file.name |
281 | | - artifact.file.seek(0) |
282 | | - shutil.copyfileobj(artifact.file, temp_file) |
283 | | - temp_file.flush() |
284 | | - |
285 | | - metadata_content = extract_wheel_metadata(temp_wheel_path) |
286 | | - if not metadata_content: |
287 | | - return None |
288 | | - |
289 | | - with tempfile.NamedTemporaryFile( |
290 | | - "wb", dir=tmp_dir, suffix=".metadata", delete=False |
291 | | - ) as temp_md: |
292 | | - temp_metadata_path = temp_md.name |
293 | | - temp_md.write(metadata_content) |
294 | | - temp_md.flush() |
295 | | - |
296 | | - metadata_artifact = Artifact.init_and_validate(temp_metadata_path) |
297 | | - try: |
298 | | - metadata_artifact.save() |
299 | | - except IntegrityError: |
300 | | - metadata_artifact = Artifact.objects.get( |
301 | | - sha256=metadata_artifact.sha256, pulp_domain=get_domain() |
302 | | - ) |
303 | | - return metadata_artifact |
304 | | - |
305 | | - finally: |
306 | | - if temp_wheel_path and os.path.exists(temp_wheel_path): |
307 | | - os.unlink(temp_wheel_path) |
308 | | - if temp_metadata_path and os.path.exists(temp_metadata_path): |
309 | | - os.unlink(temp_metadata_path) |
| 295 | + metadata_artifact.save() |
| 296 | + except IntegrityError: |
| 297 | + metadata_artifact = Artifact.objects.get( |
| 298 | + sha256=metadata_artifact.sha256, pulp_domain=get_domain() |
| 299 | + ) |
| 300 | + return metadata_artifact |
310 | 301 |
|
311 | 302 |
|
312 | 303 | def fetch_json_release_metadata(name: str, version: str, remotes: set[Remote]) -> dict: |
|
0 commit comments