3
0
Fork 0
mirror of https://github.com/YosysHQ/sby.git synced 2025-08-16 18:05:31 +00:00

Try to remove database on -f

If the database is open (based on the presence of certain files), skip deletion.
There is a (very) small window where another process *could* try to open the database at the same time that it's being deleted, but it will then fail during the database setup with `sqlite3.OperationalError: disk I/O error`, but given the failure is immediate I think it's fine.
This commit is contained in:
Krystine Sherwin 2025-07-09 09:59:22 +12:00
parent dd008ec7f7
commit baf118c838
No known key found for this signature in database
2 changed files with 19 additions and 1 deletions

View file

@ -100,6 +100,10 @@ def transaction(method: Fn) -> Fn:
return wrapper # type: ignore
class FileInUseError(Exception):
def __init__(self, *args, file: Path|str = "file"):
super().__init__(f"Found {file}, try again later", *args)
class SbyStatusDb:
def __init__(self, path: Path, task, timeout: float = 5.0, live_csv = False):
@ -529,3 +533,11 @@ def filter_latest_task_ids(all_tasks: dict[int, dict[str]]):
for task_id, task_dict in all_tasks.items():
latest[task_dict["workdir"]] = task_id
return list(latest.values())
def remove_db(path):
path = Path(path)
lock_exts = [".sqlite-wal", ".sqlite-shm"]
for lock_file in [path.with_suffix(ext) for ext in lock_exts]:
if lock_file.exists():
raise FileInUseError(file=lock_file)
os.remove(path)