Skip to content

Commit

Permalink
fix: deleting global cache prematurely with multiple files
Browse files Browse the repository at this point in the history
only delete cache dir when program exits, gracefully or not.
  • Loading branch information
avalonv committed Dec 25, 2022
1 parent bc55366 commit 0da43a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/reCBZ/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import zipfile
import re
import sys
import shutil
from pathlib import Path

import reCBZ
Expand Down Expand Up @@ -383,6 +384,14 @@ def main():
exit(1)
except wrappers.AbortedRepackError:
exit_code = 2
finally:
g_cache = reCBZ.GLOBAL_CACHEDIR
if g_cache.exists():
try:
util.mylog(f'cleanup(): {g_cache}')
shutil.rmtree(g_cache)
except PermissionError:
util.mylog(f"PermissionError, couldn't clean {g_cache}")

return exit_code

Expand Down
12 changes: 5 additions & 7 deletions src/reCBZ/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,10 @@ def add_page(self, fp, index=-1):
def remove_page(self, index):
return self._index.pop(index)

@classmethod
def cleanup(cls):
g_cache = reCBZ.GLOBAL_CACHEDIR
if g_cache.exists():
mylog(f'cleanup(): {g_cache}]')
def cleanup(self):
if self._cachedir.exists():
mylog(f'cleanup(): {self._cachedir}')
try:
shutil.rmtree(g_cache)
shutil.rmtree(self._cachedir)
except PermissionError:
mylog(f"PermissionError, couldn't clean {g_cache}")
mylog(f"PermissionError, couldn't clean {self._cachedir}")

0 comments on commit 0da43a6

Please sign in to comment.