Forgot to handle the case of import plugins creating a new file when auto-adding

This commit is contained in:
Kovid Goyal 2021-10-07 21:43:51 +05:30
parent ce1df69885
commit 92e5a55dbb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 12 additions and 4 deletions

View File

@ -230,10 +230,13 @@ def opf_metadata(opfpath):
pass pass
def forked_read_metadata(path, tdir): def forked_read_metadata(original_path, tdir):
from calibre.ebooks.metadata.opf2 import metadata_to_opf from calibre.ebooks.metadata.opf2 import metadata_to_opf
from calibre.ebooks.metadata.worker import run_import_plugins from calibre.ebooks.metadata.worker import run_import_plugins
path = run_import_plugins((path,), os.getpid(), tdir)[0] path = run_import_plugins((original_path,), os.getpid(), tdir)[0]
if path != original_path:
with lopen(os.path.join(tdir, 'file_changed_by_plugins'), 'w') as f:
f.write(os.path.abspath(path))
with lopen(path, 'rb') as f: with lopen(path, 'rb') as f:
fmt = os.path.splitext(path)[1][1:].lower() fmt = os.path.splitext(path)[1][1:].lower()
f.seek(0, 2) f.seek(0, 2)

View File

@ -229,7 +229,12 @@ class AutoAdder(QObject):
added_ids = set() added_ids = set()
for fname, tdir in data: for fname, tdir in data:
paths = [os.path.join(self.worker.path, fname)] path_to_remove = os.path.join(self.worker.path, fname)
paths = [path_to_remove]
fpath = os.path.join(tdir, 'file_changed_by_plugins')
if os.path.exists(fpath):
with open(fpath) as f:
paths[0] = f.read()
sz = os.path.join(tdir, 'size.txt') sz = os.path.join(tdir, 'size.txt')
try: try:
with open(sz, 'rb') as f: with open(sz, 'rb') as f:
@ -277,7 +282,7 @@ class AutoAdder(QObject):
duplicates.append(dups) duplicates.append(dups)
try: try:
os.remove(paths[0]) os.remove(path_to_remove)
self.worker.staging.remove(fname) self.worker.staging.remove(fname)
except: except:
import traceback import traceback