Skip to content

Commit 8d35d4b

Browse files
committed
Improve filename to hash conversion
1 parent b830393 commit 8d35d4b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/virtualship/cli/_fetch.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,18 @@ def hash_model(model: BaseModel) -> str:
3737

3838
def filename_to_hash(filename: str) -> str:
3939
"""Extract hash from filename of the format YYYYMMDD_HHMMSS_{hash}."""
40-
return filename.split("_")[-1]
40+
parts = filename.split("_")
41+
if len(parts) != 3:
42+
raise ValueError(
43+
f"Filename '{filename}' must have 3 parts delimited with underscores."
44+
)
45+
return parts[-1]
4146

4247

4348
def hash_to_filename(hash: str) -> str:
4449
"""Return a filename of the format YYYYMMDD_HHMMSS_{hash}."""
50+
if "_" in hash:
51+
raise ValueError("Hash cannot contain underscores.")
4552
return f"{datetime.now().strftime('%Y%m%d_%H%M%S')}_{hash}"
4653

4754

0 commit comments

Comments
 (0)