Skip to content

Commit

Permalink
feat(storage): add update function
Browse files Browse the repository at this point in the history
  • Loading branch information
almutlue committed Jan 17, 2025
1 parent 4c77e34 commit 3df502e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions modos/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def list(self, target: Optional[Path]) -> Generator[Path, None, None]:
def open(self, target: Path) -> io.BufferedReader:
...

@abstractmethod
def update(self, source: Path, target: Path):
"""Updates target file based on source file. If source is inside modo it will be deleted afterwards."""
...

def empty(self) -> bool:
return len(self.zarr.attrs.keys()) == 0

Expand Down Expand Up @@ -99,6 +104,10 @@ def remove(self, target: Path):
def put(self, source: Path, target: Path):
shutil.copy(source, self.path / target)

def update(self, source: Path, target: Path):
self.put(source, target)
self.remove(self.path / target)


@dataclass
class S3Path:
Expand Down Expand Up @@ -216,6 +225,12 @@ def remove(self, target: Path):
def put(self, source: Path, target: Path):
self.zarr.store.fs.put_file(source, self.path / Path(target))

def update(self, source: Path, target: Path):
if self.exists(source):
self.zarr.store.fs.mv(source, self.path / Path(target))
else:
self.put(source, target)


# Initialize object's directory given the metadata graph
def init_zarr(zarr_store: zarr.storage.Store) -> zh.Group:
Expand Down

0 comments on commit 3df502e

Please sign in to comment.