Skip to content

Commit

Permalink
clean up path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Berenbaum committed Aug 19, 2024
1 parent 03c8959 commit 64e6c82
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions dvc/dependency/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,25 @@ def dumpd(self, **kwargs) -> dict[str, Union[str, dict[str, str]]]:
def download(self, to: "Output", jobs: Optional[int] = None):
super().download(to=to, jobs=jobs)

# Save hash info to output state.
fs_info = self.fs.info(self.fs_path)
if fs_info["type"] == "directory":
for _, _, files in self.fs.walk(self.fs_path, detail=True):
for file, file_info in files.items():
path = f"{to.fs_path}{to.fs.sep}{file}"
hash_info = file_info["dvc_info"]["entry"].hash_info
to.cache.state.save(path, to.fs, hash_info)
else:
hash_info = fs_info["dvc_info"]["entry"].hash_info
to.cache.state.save(to.fs_path, to.fs, hash_info)
try:
# Save hash info to output state.
fs_info = self.fs.info(self.fs_path)
start = 0
if fs_info["type"] == "directory":
for root, _, files in self.fs.walk(self.fs_path, detail=True):
if not start:
start = len(root)
for file, file_info in files.items():
parts = [to.fs_path, *root[start:].split(to.fs.sep), file]
path = to.fs.sep.join(parts)
hash_info = file_info["dvc_info"]["entry"].hash_info
to.cache.state.save(path, to.fs, hash_info)
else:
hash_info = fs_info["dvc_info"]["entry"].hash_info
to.cache.state.save(to.fs_path, to.fs, hash_info)
except (AttributeError, KeyError):
# If no hash info found, just keep going and output will be hashed later.
pass

def update(self, rev: Optional[str] = None):
if rev:
Expand Down

0 comments on commit 64e6c82

Please sign in to comment.