Skip to content

Commit

Permalink
Fix issue where lock db_name is prefix of other db_name
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrd committed Nov 6, 2022
1 parent db055eb commit 96bbad4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions dictdatabase/locking.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ def get_lock_file_names(ddb_dir: str, db_name: str, *, id: str = None, time_ns:
"""
res = []
for x in os.listdir(ddb_dir):
if not x.startswith(db_name) or not x.endswith(".lock"):
if not x.endswith(".lock"):
continue
f_name, f_id, f_time_ns, f_stage, f_mode, _ = x.split(".")
if f_name != db_name:
continue
_, f_id, f_time_ns, f_stage, f_mode, _ = x.split(".")
if id is not None and f_id != id:
continue
if time_ns is not None and f_time_ns != str(time_ns):
Expand All @@ -55,9 +57,11 @@ def any_lock_files(ddb_dir: str, db_name: str, *, id: str = None, time_ns: int =
lock file with the given arguments.
"""
for x in os.listdir(ddb_dir):
if not x.startswith(db_name) or not x.endswith(".lock"):
if not x.endswith(".lock"):
continue
f_name, f_id, f_time_ns, f_stage, f_mode, _ = x.split(".")
if f_name != db_name:
continue
_, f_id, f_time_ns, f_stage, f_mode, _ = x.split(".")
if id is not None and f_id != id:
continue
if time_ns is not None and f_time_ns != str(time_ns):
Expand Down

0 comments on commit 96bbad4

Please sign in to comment.