Skip to content

Commit

Permalink
Merge pull request #182 from Amulet-Team/fix-cache-deletion
Browse files Browse the repository at this point in the history
Delete all cache directories that were created before a week ago
  • Loading branch information
gentlegiantJGC authored Apr 19, 2022
2 parents c7be888 + 574231a commit 0df35c7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion amulet/api/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from amulet.api.paths import get_cache_dir
from amulet import log

_path = os.path.join(get_cache_dir(), "world_temp", str(int(time.time())), "db")
_temp_path = os.path.join(get_cache_dir(), "world_temp")
_path = os.path.join(_temp_path, str(int(time.time())), "db")


_cache_db = None
Expand All @@ -20,6 +21,15 @@ def _clear_db():
_cache_db.close(compact=False)
shutil.rmtree(os.path.dirname(_path))

# remove all cache directories that were created before a week ago
# Sometimes if the program is stopped or it crashes the cleanup won't happen
for t in os.listdir(_temp_path):
if t.isnumeric() and int(t) < (time.time() - 7 * 24 * 3600):
try:
shutil.rmtree(os.path.join(_temp_path, t))
except:
pass


def get_cache_db() -> LevelDB:
global _cache_db
Expand Down

0 comments on commit 0df35c7

Please sign in to comment.