Skip to content

Commit db7f207

Browse files
committed
attempt to fix winerror access denied problem
1 parent 7ccbca2 commit db7f207

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

autointent/context/vector_index_client/cache.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33

44

55
def get_db_dir(db_dir: str | Path | None = None) -> Path:
6-
"""
7-
Get the directory path for chroma db file.
8-
Use default cache dir if not provided.
9-
Save path into user config in order to remove it from cache later.
10-
"""
11-
12-
root = Path(db_dir) if db_dir is not None else Path.cwd()
13-
db_dir = root / "vector_db" / str(uuid4()) if db_dir is None else Path(db_dir)
6+
db_dir = Path.cwd() / "vector_db" / str(uuid4()) if db_dir is None else Path(db_dir)
147
db_dir.mkdir(parents=True, exist_ok=True)
15-
168
return db_dir

autointent/context/vector_index_client/vector_index_client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22
import logging
33
import shutil
4+
import stat
5+
from collections.abc import Callable
46
from pathlib import Path
57

68
from autointent.custom_types import LabelType
@@ -107,10 +109,15 @@ def exists(self, model_name: str) -> bool:
107109
return self._get_index_dirpath(model_name) is not None
108110

109111
def delete_db(self) -> None:
110-
shutil.rmtree(self.db_dir)
112+
shutil.rmtree(self.db_dir, onexc=redo_with_write)
111113

112114

113115
class NonExistingIndexError(Exception):
114116
def __init__(self, message: str = "non-existent index was requested") -> None:
115117
self.message = message
116118
super().__init__(message)
119+
120+
121+
def redo_with_write(redo_func: Callable, path: Path, err: Exception) -> None: # noqa: ARG001
122+
Path.chmod(path, stat.S_IWRITE)
123+
redo_func(path)

0 commit comments

Comments
 (0)