mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 07:18:27 +01:00
* fs: don't use repo for jobs/hash_jobs * fs: local: exists: use fsspec's LocalFileSystem * fs: make constructor comply with fsspec
65 lines
1.6 KiB
Python
65 lines
1.6 KiB
Python
import errno
|
|
import logging
|
|
import os
|
|
|
|
from .errors import ObjectFormatError
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class HashFile:
|
|
def __init__(self, path_info, fs, hash_info):
|
|
self.path_info = path_info
|
|
self.fs = fs
|
|
self.hash_info = hash_info
|
|
|
|
@property
|
|
def size(self):
|
|
if not (self.path_info and self.fs):
|
|
return None
|
|
return self.fs.getsize(self.path_info)
|
|
|
|
def __len__(self):
|
|
return 1
|
|
|
|
def __str__(self):
|
|
return f"object {self.hash_info}"
|
|
|
|
def __bool__(self):
|
|
return bool(self.hash_info)
|
|
|
|
def __eq__(self, other):
|
|
if not isinstance(other, HashFile):
|
|
return False
|
|
return (
|
|
self.path_info == other.path_info
|
|
and self.fs == other.fs
|
|
and self.hash_info == other.hash_info
|
|
)
|
|
|
|
def check(self, odb, check_hash=True):
|
|
from .stage import get_file_hash
|
|
|
|
if not check_hash:
|
|
if not self.fs.exists(self.path_info):
|
|
raise FileNotFoundError(
|
|
errno.ENOENT, os.strerror(errno.ENOENT), self.path_info
|
|
)
|
|
else:
|
|
return None
|
|
|
|
actual = get_file_hash(
|
|
self.path_info, self.fs, self.hash_info.name, odb.state
|
|
)
|
|
|
|
logger.trace(
|
|
"cache '%s' expected '%s' actual '%s'",
|
|
self.path_info,
|
|
self.hash_info,
|
|
actual,
|
|
)
|
|
|
|
assert actual.name == self.hash_info.name
|
|
if actual.value.split(".")[0] != self.hash_info.value.split(".")[0]:
|
|
raise ObjectFormatError(f"{self} is corrupted")
|