diff --git a/src/calibre/ebooks/metadata/meta.py b/src/calibre/ebooks/metadata/meta.py index cfebcd5910..f7a9cfc412 100644 --- a/src/calibre/ebooks/metadata/meta.py +++ b/src/calibre/ebooks/metadata/meta.py @@ -230,11 +230,13 @@ def opf_metadata(opfpath): def forked_read_metadata(original_path, tdir): from calibre.ebooks.metadata.opf2 import metadata_to_opf from calibre.ebooks.metadata.worker import run_import_plugins + from calibre.utils.filenames import make_long_path_useable + path = run_import_plugins((original_path,), os.getpid(), tdir)[0] if path != original_path: with open(os.path.join(tdir, 'file_changed_by_plugins'), 'w') as f: f.write(os.path.abspath(path)) - with open(path, 'rb') as f: + with open(make_long_path_useable(path), 'rb') as f: fmt = os.path.splitext(path)[1][1:].lower() f.seek(0, 2) sz = f.tell() diff --git a/src/calibre/gui2/auto_add.py b/src/calibre/gui2/auto_add.py index 22a8c6badb..888045d4a3 100644 --- a/src/calibre/gui2/auto_add.py +++ b/src/calibre/gui2/auto_add.py @@ -6,7 +6,7 @@ import shutil import tempfile import time from qt.core import ( - QApplication, QCursor, QFileSystemWatcher, QObject, Qt, QTimer, pyqtSignal + QApplication, QCursor, QFileSystemWatcher, QObject, Qt, QTimer, pyqtSignal, ) from threading import Event, Thread @@ -15,6 +15,7 @@ from calibre.db.adding import compile_rule, filter_filename from calibre.ebooks import BOOK_EXTENSIONS from calibre.gui2 import gprefs from calibre.gui2.dialogs.duplicates import DuplicatesQuestion +from calibre.utils.filenames import make_long_path_useable from calibre.utils.tdir_in_cache import tdir_in_cache AUTO_ADDED = frozenset(BOOK_EXTENSIONS) - {'pdr', 'mbp', 'tan'} @@ -86,15 +87,18 @@ class Worker(Thread): from calibre.ebooks.metadata.opf2 import metadata_to_opf from calibre.utils.ipc.simple_worker import WorkerError, fork_job - files = [x for x in os.listdir(self.path) if + def join(*x): + return make_long_path_useable(os.path.join(*x)) + + files = [x for x in os.listdir(join(self.path)) if # Must not be in the process of being added to the db x not in self.staging and # Firefox creates 0 byte placeholder files when downloading - os.stat(os.path.join(self.path, x)).st_size > 0 and + os.stat(join(self.path, x)).st_size > 0 and # Must be a file - os.path.isfile(os.path.join(self.path, x)) and + os.path.isfile(join(self.path, x)) and # Must have read and write permissions - os.access(os.path.join(self.path, x), os.R_OK|os.W_OK) and + os.access(join(self.path, x), os.R_OK|os.W_OK) and # Must be a known ebook file type self.is_filename_allowed(x) ] @@ -104,7 +108,7 @@ class Worker(Thread): def safe_mtime(x): try: - return os.path.getmtime(os.path.join(self.path, x)) + return os.path.getmtime(join(self.path, x)) except OSError: return time.time() @@ -116,7 +120,7 @@ class Worker(Thread): # application for writing. We will get notified by # QFileSystemWatcher when writing is completed, so ignore for now. try: - open(f, 'rb').close() + open(make_long_path_useable(f), 'rb').close() except: continue tdir = tempfile.mkdtemp(dir=self.tdir) @@ -259,7 +263,7 @@ class AutoAdder(QObject): mi.tags = map_tags(mi.tags, gprefs['tag_map_on_add_rules']) if gprefs.get('author_map_on_add_rules'): from calibre.ebooks.metadata.author_mapper import ( - compile_rules, map_authors + compile_rules, map_authors, ) new_authors = map_authors(mi.authors, compile_rules(gprefs['author_map_on_add_rules'])) if new_authors != mi.authors: