Skip to content

Commit

Permalink
Fix for paths starting with tilde used for cache directory
Browse files Browse the repository at this point in the history
  • Loading branch information
sandorkertesz committed Feb 22, 2024
1 parent cbed362 commit 8a721d5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 7 additions & 0 deletions docs/release_notes/version_0.5_updates.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Version 0.5 Updates
/////////////////////////

Version 0.5.3
===============

Fixes
++++++
- fixed issue when paths starting with ~ used for :ref:`cache directories <caching>` were not correctly expanded


Version 0.5.2
===============
Expand Down
16 changes: 13 additions & 3 deletions earthkit/data/core/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,12 @@ def maximum_cache_disk_usage(self):
def file_in_cache_directory(self, path):
return path.startswith(self.directory())

@staticmethod
def _expand_path(path):
if path is not None:
path = os.path.expanduser(path)
return path


class EmptyCachePolicy(CachePolicy):
_name = "empty"
Expand Down Expand Up @@ -680,7 +686,9 @@ def managed(self):
def directory(self):
if self._dir is None:
if self._dir is None:
root_dir = self._settings.get("temporary-directory-root")
root_dir = self._expand_path(
self._settings.get("temporary-directory-root")
)
self._dir = temp_directory(dir=root_dir)
return self._dir.path

Expand All @@ -706,7 +714,7 @@ class UserCachePolicy(CachePolicy):

def __init__(self):
super().__init__()
path = self._settings.get("user-cache-directory")
path = self._expand_path(self._settings.get("user-cache-directory"))
if not os.path.exists(path):
os.makedirs(path, exist_ok=True)

Expand Down Expand Up @@ -748,7 +756,9 @@ class TmpCachePolicy(UserCachePolicy):

def __init__(self):
super().__init__()
root_dir = self._settings.get("temporary-cache-directory-root")
root_dir = self._expand_path(
self._settings.get("temporary-cache-directory-root")
)
self._dir = temp_directory(dir=root_dir)

def directory(self):
Expand Down

0 comments on commit 8a721d5

Please sign in to comment.