diff options
| author | 2024-03-28 22:25:08 +0800 | |
|---|---|---|
| committer | 2024-03-28 22:25:08 +0800 | |
| commit | 7b3e8250471103572fd1e4e6c8e6b2bed99baaba (patch) | |
| tree | 57a7633cc9732384918a1e852d52a6b07a8974d4 /src | |
| parent | 4cedc7b331f100b7dd04c98bc50a681a24389682 (diff) | |
| download | ipm-7b3e8250471103572fd1e4e6c8e6b2bed99baaba.tar.gz ipm-7b3e8250471103572fd1e4e6c8e6b2bed99baaba.zip | |
feat(hash): sync changes with hash util
Diffstat (limited to 'src')
| -rw-r--r-- | src/ipm/api.py | 2 | ||||
| -rw-r--r-- | src/ipm/models/ipk.py | 16 | ||||
| -rw-r--r-- | src/ipm/utils/freeze.py | 2 | ||||
| -rw-r--r-- | src/ipm/utils/hash.py | 2 |
4 files changed, 10 insertions, 12 deletions
diff --git a/src/ipm/api.py b/src/ipm/api.py index 1214f6c..dca7975 100644 --- a/src/ipm/api.py +++ b/src/ipm/api.py @@ -246,7 +246,7 @@ def extract( dist_path = ( Path(dist_path).resolve() if dist_path else Path(source_path).resolve().parent ) - return freeze.extract_ipk(source_path, dist_path, echo) + return freeze.extract_ipk(source_path, dist_path, None, echo) def yggdrasil_add( diff --git a/src/ipm/models/ipk.py b/src/ipm/models/ipk.py index 325c7a9..25b1bbc 100644 --- a/src/ipm/models/ipk.py +++ b/src/ipm/models/ipk.py @@ -3,6 +3,7 @@ from typing import Any, Optional, Union from tomlkit.toml_document import TOMLDocument from ipm.const import INDEX +from ipm.utils.hash import ifp_hash from ipm.models.index import Yggdrasil from ipm.models.lock import PackageLock from ipm.typing import List, Dict, Literal, StrPath @@ -11,6 +12,7 @@ from ipm.exceptions import ProjectError, TomlLoadFailed import tomlkit import abc + global_lock = PackageLock() @@ -247,19 +249,15 @@ class InfiniProject(InfiniPackage): class InfiniFrozenPackage(InfiniPackage): def __init__(self, source_path: Union[str, Path], name: str, version: str) -> None: self._source_path = Path(source_path).resolve() - - self.hash = ( - (self._source_path.parent.joinpath(self._source_path.name + ".hash")) - .read_bytes() - .hex() - ) - self._name = name self._version = version + def __hash__(self) -> str: + return ifp_hash(self._source_path) + @property - def hash_name(self) -> str: - return f"{self._source_path.name}.hash" + def hash(self) -> str: + return self.hash @property def name(self) -> str: diff --git a/src/ipm/utils/freeze.py b/src/ipm/utils/freeze.py index 2d30a0f..063d74e 100644 --- a/src/ipm/utils/freeze.py +++ b/src/ipm/utils/freeze.py @@ -68,7 +68,7 @@ def extract_ipk( dist_path = Path(dist_path).resolve() update("文件校验...", echo) - if not ifp_verify(ifp_path, hash): + if hash and not ifp_verify(ifp_path, hash): raise VerifyFailed("文件完整性验证失败!") success("文件校验成功.", echo) diff --git a/src/ipm/utils/hash.py b/src/ipm/utils/hash.py index c5cc990..6cf4eaf 100644 --- a/src/ipm/utils/hash.py +++ b/src/ipm/utils/hash.py @@ -11,6 +11,6 @@ def ifp_hash(lfp_path: StrPath, block_size=65536) -> str: return sha256.digest().hex() -def ifp_verify(lfp_path, expected_hash) -> bool: +def ifp_verify(lfp_path: StrPath, expected_hash: str) -> bool: actual_hash = ifp_hash(lfp_path) return actual_hash == expected_hash |
