Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index: md5: use hash_file #459

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 10 additions & 26 deletions src/dvc_data/index/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from dvc_objects.fs.callbacks import DEFAULT_CALLBACK

from ..hashfile.hash import DEFAULT_ALGORITHM
from ..hashfile.hash_info import HashInfo
from ..hashfile.hash import DEFAULT_ALGORITHM, hash_file
from ..hashfile.meta import Meta
from ..hashfile.tree import Tree

Expand All @@ -25,7 +24,6 @@ def md5(
name: str = DEFAULT_ALGORITHM,
check_meta: bool = True,
) -> None:
from ..hashfile.hash import fobj_md5
from .index import DataIndexEntry

entries = {}
Expand All @@ -39,37 +37,23 @@ def md5(

fs, path = index.storage_map.get_storage(entry, storage)

info = None
if check_meta:
try:
meta = Meta.from_info(fs.info(path), fs.protocol)
info = fs.info(path)
except FileNotFoundError:
continue

meta = Meta.from_info(info, fs.protocol)
if entry.meta != meta:
continue

if state:
_, hash_info = state.get(path, fs)
if hash_info:
entries[key] = DataIndexEntry(
key=entry.key,
meta=entry.meta,
hash_info=hash_info,
)
continue

with fs.open(path, "rb") as fobj:
entries[key] = DataIndexEntry(
key=entry.key,
meta=entry.meta,
hash_info=HashInfo(
name,
fobj_md5(fobj, name=name),
),
)

if state:
state.save(path, fs, entries[key].hash_info)
meta, hash_info = hash_file(path, fs, name, state=state, info=info)
entries[key] = DataIndexEntry(
key=entry.key,
meta=entry.meta,
hash_info=hash_info,
)

for key, entry in entries.items():
index[key] = entry
Expand Down