Проверить чистый экспорт и завершить аудит лабораторной 5
This commit is contained in:
@@ -4,6 +4,7 @@ import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import socket
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -13,6 +14,16 @@ import zipfile
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def remove_temporary(directory, project):
|
||||
resolved = Path(directory).resolve()
|
||||
temporary_root = Path(tempfile.gettempdir()).resolve()
|
||||
if resolved.parent != temporary_root or not resolved.name.startswith(project + '-'):
|
||||
raise RuntimeError('Temporary directory failed path validation')
|
||||
if not project.startswith('lyakhonov-lab5-repro-') or resolved == ROOT.resolve():
|
||||
raise RuntimeError('Refusing unexpected cleanup target')
|
||||
shutil.rmtree(resolved)
|
||||
|
||||
|
||||
def main():
|
||||
name = 'lyakhonov-lab5-repro-' + uuid.uuid4().hex[:8]
|
||||
directory = Path(tempfile.mkdtemp(prefix=name + '-'))
|
||||
@@ -51,6 +62,8 @@ def main():
|
||||
run(['docker', 'image', 'rm', tag], required=False)
|
||||
result = dict(project=name, directory=str(directory), port=port,
|
||||
commit=subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=ROOT, text=True).strip(), events=events)
|
||||
remove_temporary(directory, name)
|
||||
result['temporary_directory_removed'] = not directory.exists()
|
||||
(ROOT / 'evidence/reproduction.json').write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding='utf-8')
|
||||
if any(event['exit_code'] for event in events):
|
||||
raise SystemExit('Reproduction or cleanup failed; see evidence/reproduction.json')
|
||||
|
||||
Reference in New Issue
Block a user