Skip to content

Commit

Permalink
another attempt to fix permission error
Browse files Browse the repository at this point in the history
  • Loading branch information
voorhs committed Nov 12, 2024
1 parent 616ba32 commit 11bdb6f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion autointent/context/vector_index_client/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@


def get_db_dir(db_dir: str | Path | None = None) -> Path:
db_dir = Path.cwd() / "vector_db" / str(uuid4()) if db_dir is None else Path(db_dir)
db_dir = Path.cwd() / "vector_db_" + str(uuid4()) if db_dir is None else Path(db_dir)
db_dir.mkdir(parents=True, exist_ok=True)
return db_dir
18 changes: 9 additions & 9 deletions autointent/context/vector_index_client/vector_index_client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import json
import logging
import shutil
import stat
from collections.abc import Callable
from pathlib import Path
from typing import Any

from autointent.custom_types import LabelType

Expand Down Expand Up @@ -110,15 +107,18 @@ def exists(self, model_name: str) -> bool:
return self._get_index_dirpath(model_name) is not None

def delete_db(self) -> None:
shutil.rmtree(self.db_dir, onerror=redo_with_write) # type: ignore[arg-type]
path = self.db_dir / "indexes_dirnames.json"
if not path.exists():
return
with path.open() as file:
indexes_dirnames: DIRNAMES_TYPE = json.load(file)
for embedder_name in indexes_dirnames:
index = self.get_index(embedder_name)
index.delete()
shutil.rmtree(self.db_dir)


class NonExistingIndexError(Exception):
def __init__(self, message: str = "non-existent index was requested") -> None:
self.message = message
super().__init__(message)


def redo_with_write(redo_func: Callable[..., Any], path: str, err: Exception) -> None: # noqa: ARG001
Path.chmod(Path(path), stat.S_IWRITE)
redo_func(path)

0 comments on commit 11bdb6f

Please sign in to comment.