Use the cache dir for temp files created by auto-add

Idiotic windows temp file cleaners.
This commit is contained in:
Kovid Goyal 2018-03-01 18:03:33 +05:30
parent 4db8ce5f81
commit 55ad9a3c97
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -14,11 +14,11 @@ from future_builtins import map
from PyQt5.Qt import (QFileSystemWatcher, QObject, Qt, pyqtSignal, QTimer, QApplication, QCursor) from PyQt5.Qt import (QFileSystemWatcher, QObject, Qt, pyqtSignal, QTimer, QApplication, QCursor)
from calibre import prints from calibre import prints
from calibre.ptempfile import PersistentTemporaryDirectory
from calibre.db.adding import filter_filename, compile_rule from calibre.db.adding import filter_filename, compile_rule
from calibre.ebooks import BOOK_EXTENSIONS from calibre.ebooks import BOOK_EXTENSIONS
from calibre.gui2 import gprefs from calibre.gui2 import gprefs
from calibre.gui2.dialogs.duplicates import DuplicatesQuestion from calibre.gui2.dialogs.duplicates import DuplicatesQuestion
from calibre.utils.tdir_in_cache import tdir_in_cache
AUTO_ADDED = frozenset(BOOK_EXTENSIONS) - {'pdr', 'mbp', 'tan'} AUTO_ADDED = frozenset(BOOK_EXTENSIONS) - {'pdr', 'mbp', 'tan'}
@ -69,17 +69,20 @@ class Worker(Thread):
return allowed return allowed
def run(self): def run(self):
self.tdir = PersistentTemporaryDirectory('_auto_adder') self.tdir = tdir_in_cache('aa')
while self.keep_running: try:
self.wake_up.wait() while self.keep_running:
self.wake_up.clear() self.wake_up.wait()
if not self.keep_running: self.wake_up.clear()
break if not self.keep_running:
try: break
self.auto_add() try:
except: self.auto_add()
import traceback except:
traceback.print_exc() import traceback
traceback.print_exc()
finally:
shutil.rmtree(self.tdir, ignore_errors=True)
def auto_add(self): def auto_add(self):
from calibre.utils.ipc.simple_worker import fork_job, WorkerError from calibre.utils.ipc.simple_worker import fork_job, WorkerError