Skip to content

Commit 0da43a6

Browse files
committed
fix: deleting global cache prematurely with multiple files
only delete cache dir when program exits, gracefully or not.
1 parent bc55366 commit 0da43a6

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/reCBZ/__main__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import zipfile
44
import re
55
import sys
6+
import shutil
67
from pathlib import Path
78

89
import reCBZ
@@ -383,6 +384,14 @@ def main():
383384
exit(1)
384385
except wrappers.AbortedRepackError:
385386
exit_code = 2
387+
finally:
388+
g_cache = reCBZ.GLOBAL_CACHEDIR
389+
if g_cache.exists():
390+
try:
391+
util.mylog(f'cleanup(): {g_cache}')
392+
shutil.rmtree(g_cache)
393+
except PermissionError:
394+
util.mylog(f"PermissionError, couldn't clean {g_cache}")
386395

387396
return exit_code
388397

src/reCBZ/archive.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,10 @@ def add_page(self, fp, index=-1):
431431
def remove_page(self, index):
432432
return self._index.pop(index)
433433

434-
@classmethod
435-
def cleanup(cls):
436-
g_cache = reCBZ.GLOBAL_CACHEDIR
437-
if g_cache.exists():
438-
mylog(f'cleanup(): {g_cache}]')
434+
def cleanup(self):
435+
if self._cachedir.exists():
436+
mylog(f'cleanup(): {self._cachedir}')
439437
try:
440-
shutil.rmtree(g_cache)
438+
shutil.rmtree(self._cachedir)
441439
except PermissionError:
442-
mylog(f"PermissionError, couldn't clean {g_cache}")
440+
mylog(f"PermissionError, couldn't clean {self._cachedir}")

0 commit comments

Comments
 (0)