mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Windows: Make adding files whose total path length is greater than 260 characters via the Add books button work. Fixes #1900761 [Private bug](https://bugs.launchpad.net/calibre/+bug/1900761)
This commit is contained in:
parent
74be244fd9
commit
d2624dedb8
@ -5,29 +5,34 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
import shutil, os, weakref, traceback, tempfile, time
|
import os
|
||||||
from threading import Thread
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
import time
|
||||||
|
import traceback
|
||||||
|
import weakref
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from polyglot.builtins import iteritems, map, unicode_type, string_or_bytes
|
|
||||||
|
|
||||||
from PyQt5.Qt import QObject, Qt, pyqtSignal
|
from PyQt5.Qt import QObject, Qt, pyqtSignal
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
from calibre import prints, as_unicode
|
from calibre import as_unicode, prints
|
||||||
from calibre.constants import DEBUG, iswindows, ismacos, filesystem_encoding
|
from calibre.constants import DEBUG, filesystem_encoding, ismacos, iswindows
|
||||||
from calibre.customize.ui import run_plugins_on_postimport, run_plugins_on_postadd
|
from calibre.customize.ui import run_plugins_on_postadd, run_plugins_on_postimport
|
||||||
from calibre.db.adding import find_books_in_directory, compile_rule
|
from calibre.db.adding import compile_rule, find_books_in_directory
|
||||||
from calibre.db.utils import find_identical_books
|
from calibre.db.utils import find_identical_books
|
||||||
from calibre.ebooks.metadata import authors_to_sort_string
|
from calibre.ebooks.metadata import authors_to_sort_string
|
||||||
from calibre.ebooks.metadata.book.base import Metadata
|
from calibre.ebooks.metadata.book.base import Metadata
|
||||||
from calibre.ebooks.metadata.opf2 import OPF
|
from calibre.ebooks.metadata.opf2 import OPF
|
||||||
from calibre.gui2 import error_dialog, warning_dialog, gprefs
|
from calibre.gui2 import error_dialog, gprefs, warning_dialog
|
||||||
from calibre.gui2.dialogs.duplicates import DuplicatesQuestion
|
from calibre.gui2.dialogs.duplicates import DuplicatesQuestion
|
||||||
from calibre.gui2.dialogs.progress import ProgressDialog
|
from calibre.gui2.dialogs.progress import ProgressDialog
|
||||||
from calibre.ptempfile import PersistentTemporaryDirectory
|
from calibre.ptempfile import PersistentTemporaryDirectory
|
||||||
from calibre.utils import join_with_timeout
|
from calibre.utils import join_with_timeout
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
from calibre.utils.ipc.pool import Pool, Failure
|
from calibre.utils.filenames import make_long_path_useable
|
||||||
|
from calibre.utils.ipc.pool import Failure, Pool
|
||||||
|
from polyglot.builtins import iteritems, map, string_or_bytes, unicode_type
|
||||||
from polyglot.queue import Empty
|
from polyglot.queue import Empty
|
||||||
|
|
||||||
|
|
||||||
@ -61,6 +66,10 @@ class Adder(QObject):
|
|||||||
do_one_signal = pyqtSignal()
|
do_one_signal = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, source, single_book_per_directory=True, db=None, parent=None, callback=None, pool=None, list_of_archives=False):
|
def __init__(self, source, single_book_per_directory=True, db=None, parent=None, callback=None, pool=None, list_of_archives=False):
|
||||||
|
if isinstance(source, str):
|
||||||
|
source = make_long_path_useable(source)
|
||||||
|
else:
|
||||||
|
source = list(map(make_long_path_useable, source))
|
||||||
if not validate_source(source, parent):
|
if not validate_source(source, parent):
|
||||||
return
|
return
|
||||||
QObject.__init__(self, parent)
|
QObject.__init__(self, parent)
|
||||||
|
@ -222,7 +222,14 @@ def run_file_dialog(
|
|||||||
return ()
|
return ()
|
||||||
if parts[0] != secret:
|
if parts[0] != secret:
|
||||||
raise Exception('File dialog failed, incorrect secret received: ' + get_errors())
|
raise Exception('File dialog failed, incorrect secret received: ' + get_errors())
|
||||||
ans = tuple((os.path.abspath(x.decode('utf-8')) for x in parts[1:]))
|
|
||||||
|
from calibre_extensions.winutil import get_long_path_name
|
||||||
|
|
||||||
|
def fix_path(x):
|
||||||
|
u = os.path.abspath(x.decode('utf-8'))
|
||||||
|
return get_long_path_name(u)
|
||||||
|
|
||||||
|
ans = tuple(map(fix_path, parts[1:]))
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
|
|
||||||
|
@ -592,3 +592,14 @@ def copytree_using_links(path, dest, dest_is_parent=True, filecopyfunc=copyfile)
|
|||||||
|
|
||||||
|
|
||||||
rmtree = shutil.rmtree
|
rmtree = shutil.rmtree
|
||||||
|
|
||||||
|
|
||||||
|
if iswindows:
|
||||||
|
def make_long_path_useable(path):
|
||||||
|
if len(path) > 200:
|
||||||
|
from calibre_extensions.winutil import canonicalize_path
|
||||||
|
path = canonicalize_path(path)
|
||||||
|
return path
|
||||||
|
else:
|
||||||
|
def make_long_path_useable(path):
|
||||||
|
return path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user