Skip to content

Commit 2781211

Browse files
committed
Only delete problem zip after detecting problem directory
Otherwise, if you only have the zip, it gets deleted and then the script fails, leaving you without the data of that problem. In my case, I didn't notice, and ran `import-contest` again after unzipping all problem archives, which then failed because the first problem was missing.
1 parent 3b5b815 commit 2781211

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

misc-tools/import-contest.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ if os.path.exists('problems.yaml') or os.path.exists('problems.json') or os.path
216216
confirmIndividually = dj_utils.confirm("Confirm individually for every problem", False)
217217
for problem in problems:
218218
print(f'\nPreparing problem \'{problem}\'.')
219-
if os.path.exists(f'{problem}.zip'):
220-
os.unlink(f'{problem}.zip')
221219
if not os.path.isdir(problem) or not os.path.isfile(f'{problem}/problem.yaml'):
222220
print('Problem directory not found or doesn\'t contain a problem.yaml.')
223221
exit(3)
222+
if os.path.exists(f'{problem}.zip'):
223+
os.unlink(f'{problem}.zip')
224224
zip_command = f"zip -r '../{problem}' -- .timelimit *"
225225
process = subprocess.Popen(zip_command, cwd=problem, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, shell=True)
226226

0 commit comments

Comments
 (0)