2022-01-13 20:49:26 +01:00
|
|
|
from pathlib import Path
|
|
|
|
from PyTeX.errors import *
|
|
|
|
from .checksum import md5
|
|
|
|
from typing import Optional, List, Dict
|
|
|
|
|
|
|
|
|
|
|
|
def ensure_file_integrity(file: Path, output_file_name: str, build_info: Optional[List[Dict]] = None):
|
|
|
|
if file.exists():
|
|
|
|
if not build_info:
|
2022-01-13 21:12:35 +01:00
|
|
|
raise UnknownFileInBuildDirectoryNoOverwriteError(str(file))
|
2022-01-13 20:49:26 +01:00
|
|
|
found = False
|
|
|
|
for info in build_info:
|
|
|
|
if info['name'] == output_file_name:
|
|
|
|
if not md5(file) == info['md5sum']:
|
|
|
|
raise ModifiedFileInBuildDirectoryError(str(file))
|
|
|
|
found = True
|
|
|
|
if not found:
|
2022-01-13 21:12:35 +01:00
|
|
|
raise UnknownFileInBuildDirectoryNoOverwriteError(str(file))
|