mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Handle long paths when auto adding better
Havent really tested it since long paths arent officially supported but this *should* mostly work
This commit is contained in:
parent
cd13fbfe27
commit
2fc2b59331
@ -230,11 +230,13 @@ def opf_metadata(opfpath):
|
|||||||
def forked_read_metadata(original_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
|
||||||
|
from calibre.utils.filenames import make_long_path_useable
|
||||||
|
|
||||||
path = run_import_plugins((original_path,), os.getpid(), tdir)[0]
|
path = run_import_plugins((original_path,), os.getpid(), tdir)[0]
|
||||||
if path != original_path:
|
if path != original_path:
|
||||||
with open(os.path.join(tdir, 'file_changed_by_plugins'), 'w') as f:
|
with open(os.path.join(tdir, 'file_changed_by_plugins'), 'w') as f:
|
||||||
f.write(os.path.abspath(path))
|
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()
|
fmt = os.path.splitext(path)[1][1:].lower()
|
||||||
f.seek(0, 2)
|
f.seek(0, 2)
|
||||||
sz = f.tell()
|
sz = f.tell()
|
||||||
|
@ -6,7 +6,7 @@ import shutil
|
|||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
from qt.core import (
|
from qt.core import (
|
||||||
QApplication, QCursor, QFileSystemWatcher, QObject, Qt, QTimer, pyqtSignal
|
QApplication, QCursor, QFileSystemWatcher, QObject, Qt, QTimer, pyqtSignal,
|
||||||
)
|
)
|
||||||
from threading import Event, Thread
|
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.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.filenames import make_long_path_useable
|
||||||
from calibre.utils.tdir_in_cache import tdir_in_cache
|
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'}
|
||||||
@ -86,15 +87,18 @@ class Worker(Thread):
|
|||||||
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
from calibre.ebooks.metadata.opf2 import metadata_to_opf
|
||||||
from calibre.utils.ipc.simple_worker import WorkerError, fork_job
|
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
|
# Must not be in the process of being added to the db
|
||||||
x not in self.staging and
|
x not in self.staging and
|
||||||
# Firefox creates 0 byte placeholder files when downloading
|
# 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
|
# 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
|
# 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
|
# Must be a known ebook file type
|
||||||
self.is_filename_allowed(x)
|
self.is_filename_allowed(x)
|
||||||
]
|
]
|
||||||
@ -104,7 +108,7 @@ class Worker(Thread):
|
|||||||
|
|
||||||
def safe_mtime(x):
|
def safe_mtime(x):
|
||||||
try:
|
try:
|
||||||
return os.path.getmtime(os.path.join(self.path, x))
|
return os.path.getmtime(join(self.path, x))
|
||||||
except OSError:
|
except OSError:
|
||||||
return time.time()
|
return time.time()
|
||||||
|
|
||||||
@ -116,7 +120,7 @@ class Worker(Thread):
|
|||||||
# application for writing. We will get notified by
|
# application for writing. We will get notified by
|
||||||
# QFileSystemWatcher when writing is completed, so ignore for now.
|
# QFileSystemWatcher when writing is completed, so ignore for now.
|
||||||
try:
|
try:
|
||||||
open(f, 'rb').close()
|
open(make_long_path_useable(f), 'rb').close()
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
tdir = tempfile.mkdtemp(dir=self.tdir)
|
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'])
|
mi.tags = map_tags(mi.tags, gprefs['tag_map_on_add_rules'])
|
||||||
if gprefs.get('author_map_on_add_rules'):
|
if gprefs.get('author_map_on_add_rules'):
|
||||||
from calibre.ebooks.metadata.author_mapper import (
|
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']))
|
new_authors = map_authors(mi.authors, compile_rules(gprefs['author_map_on_add_rules']))
|
||||||
if new_authors != mi.authors:
|
if new_authors != mi.authors:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user