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)

This commit is contained in:
Kovid Goyal 2026-02-14 10:29:55 +05:30
parent e44e03679b
commit 4a22dd0da1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 22 additions and 4 deletions

View File

@ -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'],
}

View File

@ -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: