Skip to content

Commit

Permalink
fix: lpath download cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rteqs committed Dec 2, 2024
1 parent b461fa0 commit 77f2cae
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ Types of changes

### Fixed

* Bug in `LPath` download throws an exception when version id is null

## 2.54.4 - 2024-11-25

### Fixed

* Fix pagination in `TableUpdater.list_records` to not OOM when table size is too large

## 2.54.4 - 2024-11-25
Expand Down
35 changes: 20 additions & 15 deletions src/latch/ldata/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
import os
import re
import shutil
import sys
from collections.abc import Iterator
from dataclasses import dataclass, field
from pathlib import Path
import sys
from typing import Iterator, Optional, Type
from typing import Optional, Type

import gql
import xattr
from flytekit import (
Blob,
BlobMetadata,
Expand All @@ -19,7 +21,6 @@
)
from flytekit.extend import TypeEngine, TypeTransformer
from typing_extensions import Self
import xattr

from latch.ldata.type import LatchPathError, LDataNodeType
from latch_cli.utils import urljoins
Expand Down Expand Up @@ -69,11 +70,7 @@ class LPath:
"""

_cache: _Cache = field(
default_factory=_Cache,
init=False,
repr=False,
hash=False,
compare=False,
default_factory=_Cache, init=False, repr=False, hash=False, compare=False
)

path: str
Expand Down Expand Up @@ -118,7 +115,7 @@ def fetch_metadata(self) -> None:
or data["ldataNode"] is None
or (data["path"] is not None and data["path"] != "")
):
raise LatchPathError(f"no such Latch file or directory", self.path)
raise LatchPathError("no such Latch file or directory", self.path)

self._clear_cache()

Expand All @@ -137,7 +134,6 @@ def fetch_metadata(self) -> None:
self._cache.content_type = meta["contentType"]
self._cache.version_id = meta["versionId"]


def _clear_cache(self):
self._cache.path = None
self._cache.node_id = None
Expand Down Expand Up @@ -230,7 +226,7 @@ def iterdir(self) -> Iterator[Self]:
)["ldataResolvePathData"]

if data is None:
raise LatchPathError(f"no such Latch file or directory", {self.path})
raise LatchPathError(f"no such Latch file or directory, {self.path}")
if data["finalLinkTarget"]["type"].lower() not in _dir_types:
raise ValueError(f"not a directory: {self.path}")

Expand Down Expand Up @@ -303,7 +299,11 @@ def upload_from(self, src: Path, *, show_progress_bar: bool = False) -> None:
self._clear_cache()

def download(
self, dst: Optional[Path] = None, *, show_progress_bar: bool = False, cache: bool = False
self,
dst: Optional[Path] = None,
*,
show_progress_bar: bool = False,
cache: bool = False,
) -> Path:
"""Download the file at this instance's path to the given destination.
Expand All @@ -328,7 +328,12 @@ def download(

self._clear_cache()
version_id = self.version_id()
if not_windows and cache and dst.exists() and version_id == xattr.getxattr(dst_str, 'user.version_id').decode():
if (
not_windows
and cache
and dst.exists()
and version_id == xattr.getxattr(dst_str, "user.version_id").decode()
):
return dst

_download(
Expand All @@ -339,8 +344,8 @@ def download(
confirm_overwrite=False,
)

if not_windows:
xattr.setxattr(dst_str, 'user.version_id', version_id)
if not_windows and version_id is not None:
xattr.setxattr(dst_str, "user.version_id", version_id)

return dst

Expand Down

0 comments on commit 77f2cae

Please sign in to comment.