From 4a22dd0da1d77f447432dbe96cf7a1330bf509fa Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 14 Feb 2026 10:29:55 +0530 Subject: [PATCH] Hanvon N10 device driver: Fix calibre unable to put its metadata files onto the device. Fixes #2141625 [calibre-9.1 fails to put metadata to Hanvon N10 pro 2](https://bugs.launchpad.net/calibre/+bug/2141625) --- src/calibre/devices/mtp/defaults.py | 5 ++++- src/calibre/devices/mtp/driver.py | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/calibre/devices/mtp/defaults.py b/src/calibre/devices/mtp/defaults.py index b8e56d4844..9321713a23 100644 --- a/src/calibre/devices/mtp/defaults.py +++ b/src/calibre/devices/mtp/defaults.py @@ -11,7 +11,10 @@ import traceback from calibre.constants import iswindows supernote_settings = { - 'calibre_file_paths': {'metadata':'Document/metadata.calibre', 'driveinfo':'Document/driveinfo.calibre'}, + 'calibre_file_paths': { + 'metadata': ['Document/metadata.calibre', 'Documents/metadata.calibre'], + 'driveinfo': ['Document/driveinfo.calibre', 'Documents/driveinfo.calibre'], + }, 'send_to': ['Document', 'Documents'], } diff --git a/src/calibre/devices/mtp/driver.py b/src/calibre/devices/mtp/driver.py index b2be64a2b9..61f1cf6e62 100644 --- a/src/calibre/devices/mtp/driver.py +++ b/src/calibre/devices/mtp/driver.py @@ -204,8 +204,23 @@ class MTP_DEVICE(BASE): if self.is_mtp_device_connected: self.eject() + def find_calibre_file_path(self, storage, key) -> list[str]: + paths = self.calibre_file_paths[key] + if isinstance(paths, str): + paths = (paths,) + if len(paths) == 1: + return paths[0].split('/') + # Find the first path whose parent directory exists + for candidate in paths: + path = candidate.split('/') + if len(path) == 1: + return path + if storage.find_path(path[:-1]) is not None: + return path + return paths[0].split('/') + def put_calibre_file(self, storage, key, stream, size): - path = self.calibre_file_paths[key].split('/') + path = self.find_calibre_file_path(storage, key) parent = self.ensure_parent(storage, path) self.put_file(parent, path[-1], stream, size) @@ -215,7 +230,7 @@ class MTP_DEVICE(BASE): from calibre.utils.config import from_json, to_json from calibre.utils.date import isoformat, now - f = storage.find_path(self.calibre_file_paths['driveinfo'].split('/')) + f = storage.find_path(self.find_calibre_file_path(storage, 'driveinfo')) dinfo = {} if f is not None: try: @@ -291,7 +306,7 @@ class MTP_DEVICE(BASE): self.report_progress(0, _('Reading e-book metadata')) # Read the cache if it exists storage = self.filesystem_cache.storage(sid) - cache = storage.find_path(self.calibre_file_paths['metadata'].split('/')) + cache = storage.find_path(self.find_calibre_file_path(storage, 'metadata')) if cache is not None: json_codec = JSONCodec() try: