Skip to content

Commit c521977

Browse files
author
Thomas Desveaux
committed
artifacts: fix create_torrent
torf check if file exists, move active detection before instantiate of Torrent object
1 parent dbc228e commit c521977

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

nimp/artifacts.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,16 @@ def create_torrent(artifact_path: StrPathLike, announce: str | None, dry_run: bo
332332
artifact_path = Path(artifact_path)
333333

334334
torrent_path = artifact_path.with_suffix('.torrent')
335-
tmp_torrent_path = torrent_path.with_suffix('.tmp')
335+
tmp_torrent_path = torrent_path.with_suffix('.torrent.tmp')
336336
if not dry_run:
337337
tmp_torrent_path.unlink(missing_ok=True)
338338
torrent_path.unlink(missing_ok=True)
339339

340+
if (artifact_archive_path := artifact_path.with_suffix('.zip')) and artifact_archive_path.is_file():
341+
artifact_path = artifact_archive_path
342+
elif not artifact_path.is_dir():
343+
raise FileNotFoundError(f'Artifact not found: {artifact_path}')
344+
340345
torrent = torf.Torrent(
341346
path=artifact_path,
342347
name=artifact_path.name,
@@ -346,11 +351,6 @@ def create_torrent(artifact_path: StrPathLike, announce: str | None, dry_run: bo
346351
private=False,
347352
piece_size=32768,
348353
)
349-
if (artifact_archive_path := artifact_path.with_suffix('.zip')) and artifact_archive_path.is_file():
350-
torrent.name = artifact_archive_path.name
351-
torrent.path = artifact_archive_path
352-
elif not artifact_path.is_dir():
353-
raise FileNotFoundError(f'Artifact not found: {artifact_path}')
354354

355355
if not dry_run:
356356
if not torrent.generate():

0 commit comments

Comments
 (0)