refactor: clear health check args generation
This commit is contained in:
parent
38f0bc8598
commit
855b35592f
|
@ -40,7 +40,7 @@ def get_health_check_args(repo_conf: repo.Config) -> List[str]:
|
||||||
"-root=.",
|
"-root=.",
|
||||||
f"-repoSize={str(repo_conf.max_size)}",
|
f"-repoSize={str(repo_conf.max_size)}",
|
||||||
*[f"-meta={meta}" for meta in repo_conf.files.required],
|
*[f"-meta={meta}" for meta in repo_conf.files.required],
|
||||||
get_hash(repo_conf),
|
f"-checkFileSumList={','.join(get_hashs(repo_conf))}",
|
||||||
f"-checkFileNameList={','.join(repo_conf.files.immutable)}",
|
f"-checkFileNameList={','.join(repo_conf.files.immutable)}",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -97,16 +97,15 @@ def get_health_check_stage(repo_conf: repo.Config) -> result.StageDetail:
|
||||||
def calc_sha256sum(file_path: Path) -> str:
|
def calc_sha256sum(file_path: Path) -> str:
|
||||||
sha256_hash = hashlib.sha256()
|
sha256_hash = hashlib.sha256()
|
||||||
with open(file_path, "rb") as f:
|
with open(file_path, "rb") as f:
|
||||||
for byte_block in iter(lambda: f.read(65536 * 2), b""):
|
for byte_block in iter(lambda: f.read(64 * 1024), b""):
|
||||||
sha256_hash.update(byte_block)
|
sha256_hash.update(byte_block)
|
||||||
return sha256_hash.hexdigest()
|
return sha256_hash.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def get_hash(repo_conf: repo.Config) -> str: # input should be a list
|
def get_hashs(repo_conf: repo.Config) -> List[str]:
|
||||||
base_dir = (repo_conf.root / repo_conf.path).parent
|
base_dir = (repo_conf.root / repo_conf.path).parent
|
||||||
immutable_dir = base_dir / "immutable_files"
|
immutable_dir = base_dir / "immutable_files"
|
||||||
immutable_files = [
|
immutable_files = [
|
||||||
immutable_dir / Path(file).name for file in repo_conf.files.immutable
|
immutable_dir / Path(file).name for file in repo_conf.files.immutable
|
||||||
]
|
]
|
||||||
immutable_hash = [calc_sha256sum(file) for file in immutable_files]
|
return [calc_sha256sum(file) for file in immutable_files]
|
||||||
return f"-checkFileSumList={','.join(immutable_hash)}"
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user