diff --git a/tests/conftest.py b/tests/conftest.py index a1ce455..d8308b6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -31,7 +31,7 @@ @pytest.fixture def fs(): - fs = V3ioFS(cache_validity_seconds=0) + fs = V3ioFS() yield fs fs._client.close() diff --git a/v3iofs/file.py b/v3iofs/file.py index 21d9cde..775fc35 100644 --- a/v3iofs/file.py +++ b/v3iofs/file.py @@ -58,10 +58,4 @@ def _upload_chunk(self, final=False): def _initiate_upload(self): """ Create remote file/upload """ - client: Client = self.fs._client - container, path = split_container(self.path) - client.object.delete( - container=container, - path=path, - raise_for_status=v3io.dataplane.RaiseForStatus.never, - ) + self.fs.rm_file(self.path) diff --git a/v3iofs/fs.py b/v3iofs/fs.py index 9d035e3..67f5f6e 100644 --- a/v3iofs/fs.py +++ b/v3iofs/fs.py @@ -59,11 +59,20 @@ def get(self, key): return None + def delete_if_exists(self, key): + self._cache.pop(key, None) + def _gc(self, until): for key_time, key in self._time_to_key: num_removed = 0 if key_time > until + self._cache_validity_seconds or len(self._cache) > self._capacity: - del self._cache[key] + result = self._cache.get(key, None) + if result: + cache_time, value = result + # cache entry may have been deleted and re-added + if cache_time == key_time: + del self._cache[key] + num_removed += 1 else: break @@ -178,13 +187,13 @@ def copy(self, path1, path2, **kwargs): ... # FIXME def _rm(self, path): - container, path = split_container(path) + container, path_without_container = split_container(path) if not container: raise ValueError(f'bad path: {path:r}') resp = self._client.delete_object( container=container, - path=path, + path=path_without_container, raise_for_status=v3io.dataplane.RaiseForStatus.never, ) @@ -193,6 +202,9 @@ def _rm(self, path): raise Exception( f'{resp.status_code} received while accessing {path!r}') + if self._cache: + self._cache.delete_if_exists(path) + def touch(self, path, truncate=True, **kwargs): if not truncate: # TODO raise ValueError('only truncate touch supported')