Skip to content

Commit

Permalink
meta: add version_id
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrowla authored and efiop committed Aug 30, 2022
1 parent 5654d2b commit 5f6ba22
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/dvc_data/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def info(self, path, **kwargs):
"name": path,
"size": entry.meta.size if entry.meta else 0,
"isexec": entry.meta.isexec if entry.meta else False,
"version_id": entry.meta.version_id if entry.meta else None,
"isdvc": True,
"isout": True,
"obj": entry.obj,
Expand All @@ -126,6 +127,7 @@ def info(self, path, **kwargs):
"name": path,
"size": 0,
"isexec": False,
"version_id": None,
"isdvc": bool(self.index.longest_prefix(key)),
"isout": False,
"obj": None,
Expand Down
8 changes: 7 additions & 1 deletion src/dvc_data/hashfile/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def _adapt_info(info: Dict[str, Any], scheme: str) -> Dict[str, Any]:
"ETag" in info or "Content-MD5" in info
):
info["checksum"] = info.get("ETag") or info.get("Content-MD5")
if scheme == "s3" and "VersionId" in info:
info["version_id"] = info["VersionId"]
return info


Expand Down Expand Up @@ -190,5 +192,9 @@ def hash_file(
assert ".dir" not in hash_info.value
state.save(path, fs, hash_info)

meta = Meta(size=info["size"], isexec=is_exec(info.get("mode", 0)))
meta = Meta(
size=info["size"],
isexec=is_exec(info.get("mode", 0)),
version_id=info.get("version_id"),
)
return meta, hash_info
3 changes: 3 additions & 0 deletions src/dvc_data/hashfile/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ class Meta:
PARAM_SIZE: ClassVar[str] = "size"
PARAM_NFILES: ClassVar[str] = "nfiles"
PARAM_ISEXEC: ClassVar[str] = "isexec"
PARAM_VERSION_ID: ClassVar[str] = "version_id"

size: Optional[int] = None
nfiles: Optional[int] = None
isexec: bool = False
version_id: Optional[str] = None

@classmethod
def from_dict(cls, d: Dict[str, Any]) -> "Meta":
Expand All @@ -24,6 +26,7 @@ def from_dict(cls, d: Dict[str, Any]) -> "Meta":
size=d.pop(cls.PARAM_SIZE, None),
nfiles=d.pop(cls.PARAM_NFILES, None),
isexec=d.pop(cls.PARAM_ISEXEC, False),
version_id=d.pop(cls.PARAM_VERSION_ID, None),
)

def to_dict(self) -> Dict[str, Any]:
Expand Down

0 comments on commit 5f6ba22

Please sign in to comment.