Skip to content

Commit

Permalink
rename dir to dir_path to avoid conflict with builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
mjurbanski-reef committed Jan 3, 2024
1 parent 610cdc2 commit e38b7d3
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions b2/_internal/_cli/autocomplete_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ def current_state_identifier(self) -> str:
class HomeCachePickleStore(PickleStore):
_dir: pathlib.Path

def __init__(self, dir: pathlib.Path | None = None) -> None:
self._dir = dir
def __init__(self, dir_path: pathlib.Path | None = None) -> None:
self._dir = dir_path

def _cache_dir(self) -> pathlib.Path:
if self._dir:
return self._dir
self._dir = pathlib.Path(
platformdirs.user_cache_dir(appname='b2', appauthor='backblaze')
) / 'autocomplete'
if not self._dir:
self._dir = pathlib.Path(
platformdirs.user_cache_dir(appname='b2', appauthor='backblaze')
) / 'autocomplete'
return self._dir

def _fname(self, identifier: str) -> str:
Expand All @@ -74,10 +73,10 @@ def set_pickle(self, identifier: str, data: bytes) -> None:
"""Sets the pickle for identifier if it doesn't exist.
When a new pickle is added, old ones are removed."""

dir = self._cache_dir()
os.makedirs(dir, exist_ok=True)
path = dir / self._fname(identifier)
for file in dir.glob('b2-autocomplete-cache-*.pickle'):
dir_path = self._cache_dir()
dir_path.mkdir(parents=True, exist_ok=True)
path = dir_path / self._fname(identifier)
for file in dir_path.glob('b2-autocomplete-cache-*.pickle'):
file.unlink()
with open(path, 'wb') as f:
f.write(data)
Expand Down

0 comments on commit e38b7d3

Please sign in to comment.