Skip to content

Commit 7eedff3

Browse files
committed
Keep pickle lockfiles out of cache dirs
1 parent 4d6b04f commit 7eedff3

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/cachier/cores/pickle.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Licensed under the MIT license:
77
# http://www.opensource.org/licenses/MIT-license
88
# Copyright (c) 2016, Shay Palachy <shaypal5@gmail.com>
9+
import hashlib
910
import logging
1011
import os
1112
import pickle # for local caching
@@ -106,7 +107,10 @@ def cache_fpath(self) -> str:
106107

107108
@property
108109
def _shared_lock_fpath(self) -> str:
109-
return f"{self.cache_fpath}{self._SHARED_LOCK_SUFFIX}"
110+
lock_dir = os.path.join(tempfile.gettempdir(), "cachier-locks")
111+
os.makedirs(lock_dir, exist_ok=True)
112+
cache_hash = hashlib.sha256(self.cache_fpath.encode("utf-8")).hexdigest()
113+
return os.path.join(lock_dir, f"{cache_hash}{self._SHARED_LOCK_SUFFIX}")
110114

111115
@staticmethod
112116
def _convert_legacy_cache_entry(
@@ -285,6 +289,7 @@ async def amark_entry_being_calculated(self, key: str) -> None:
285289
def mark_entry_not_calculated(self, key: str) -> None:
286290
if self.separate_files:
287291
self._mark_entry_not_calculated_separate_files(key)
292+
return # pragma: no cover
288293
with self.lock:
289294
cache = self.get_cache_dict()
290295
# that's ok, we don't need an entry in that case

0 commit comments

Comments
 (0)