mirror of
https://github.com/MoreTore/openpilot.git
synced 2026-10-01 03:43:51 +08:00
add mypy check for return-any (#24379)
* add mypy check for return-any
* remove unused import
* typing
* remove unnecessary variable typing
* cleanup
* cleanup
* bump submodules
* small fixes
* only a problem on mac
Co-authored-by: Willem Melching <willem.melching@gmail.com>
old-commit-hash: d2eef1955c
This commit is contained in:
@@ -7,7 +7,7 @@ import struct
|
||||
import subprocess
|
||||
import time
|
||||
import os
|
||||
from typing import Generator
|
||||
from typing import Dict, Generator, Union
|
||||
|
||||
SPARSE_CHUNK_FMT = struct.Struct('H2xI4x')
|
||||
|
||||
@@ -99,26 +99,30 @@ def get_partition_path(target_slot_number: int, partition: dict) -> str:
|
||||
return path
|
||||
|
||||
|
||||
def verify_partition(target_slot_number: int, partition: dict) -> bool:
|
||||
def verify_partition(target_slot_number: int, partition: Dict[str, Union[str, int]]) -> bool:
|
||||
full_check = partition['full_check']
|
||||
path = get_partition_path(target_slot_number, partition)
|
||||
partition_size = partition['size']
|
||||
if not isinstance(partition['size'], int):
|
||||
return False
|
||||
partition_size: int = partition['size']
|
||||
|
||||
if not isinstance(partition['hash_raw'], str):
|
||||
return False
|
||||
partition_hash: str = partition['hash_raw']
|
||||
with open(path, 'rb+') as out:
|
||||
if full_check:
|
||||
raw_hash = hashlib.sha256()
|
||||
|
||||
pos = 0
|
||||
chunk_size = 1024 * 1024
|
||||
pos, chunk_size = 0, 1024 * 1024
|
||||
while pos < partition_size:
|
||||
n = min(chunk_size, partition_size - pos)
|
||||
raw_hash.update(out.read(n))
|
||||
pos += n
|
||||
|
||||
return raw_hash.hexdigest().lower() == partition['hash_raw'].lower()
|
||||
return raw_hash.hexdigest().lower() == partition_hash.lower()
|
||||
else:
|
||||
out.seek(partition_size)
|
||||
return out.read(64) == partition['hash_raw'].lower().encode()
|
||||
return out.read(64) == partition_hash.lower().encode()
|
||||
|
||||
|
||||
def clear_partition_hash(target_slot_number: int, partition: dict) -> None:
|
||||
|
||||
Reference in New Issue
Block a user