@@ -273,40 +273,32 @@ def artifact_to_metadata_artifact(
273273
274274 temp_wheel_path = None
275275 temp_metadata_path = None
276+
277+ with tempfile .NamedTemporaryFile ("wb" , dir = tmp_dir , suffix = filename , delete = False ) as temp_file :
278+ temp_wheel_path = temp_file .name
279+ artifact .file .seek (0 )
280+ shutil .copyfileobj (artifact .file , temp_file )
281+ temp_file .flush ()
282+
283+ metadata_content = extract_wheel_metadata (temp_wheel_path )
284+ if not metadata_content :
285+ return None
286+
287+ with tempfile .NamedTemporaryFile (
288+ "wb" , dir = tmp_dir , suffix = ".metadata" , delete = False
289+ ) as temp_md :
290+ temp_metadata_path = temp_md .name
291+ temp_md .write (metadata_content )
292+ temp_md .flush ()
293+
294+ metadata_artifact = Artifact .init_and_validate (temp_metadata_path )
276295 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 )
296+ metadata_artifact .save ()
297+ except IntegrityError :
298+ metadata_artifact = Artifact .objects .get (
299+ sha256 = metadata_artifact .sha256 , pulp_domain = get_domain ()
300+ )
301+ return metadata_artifact
310302
311303
312304def fetch_json_release_metadata (name : str , version : str , remotes : set [Remote ]) -> dict :
0 commit comments