Windows: MTP driver: Fix a regression in the previous release that caused an error with some devices. Fixes #2073323 [Kindle Device Error Communicating with Device](https://bugs.launchpad.net/calibre/+bug/2073323)

This commit is contained in:
Kovid Goyal 2024-07-18 15:15:00 +05:30
parent bbf9e7c0e2
commit 75d111e3f6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -16,6 +16,7 @@ from operator import attrgetter
from typing import Dict, Tuple from typing import Dict, Tuple
from calibre import force_unicode, human_readable, prints from calibre import force_unicode, human_readable, prints
from calibre.constants import iswindows
from calibre.ebooks import BOOK_EXTENSIONS from calibre.ebooks import BOOK_EXTENSIONS
from calibre.utils.date import as_utc, local_tz from calibre.utils.date import as_utc, local_tz
from calibre.utils.icu import lower, sort_key from calibre.utils.icu import lower, sort_key
@ -75,9 +76,15 @@ class FileOrFolder:
self.files = [] self.files = []
self.folders = [] self.folders = []
if not self.is_storage: if not self.is_storage:
# storage ids can overlap filesystem object ids. See https://bugs.launchpad.net/bugs/2072384 # storage ids can overlap filesystem object ids on libmtp. See https://bugs.launchpad.net/bugs/2072384
# so only store actual filesystem object ids in id_map # so only store actual filesystem object ids in id_map
fs_cache.id_maps[self.storage_id][self.object_id] = self fs_cache.id_maps[self.storage_id][self.object_id] = self
if iswindows:
# On windows parent_id == storage_id for objects in root. Set
# it 0 so the rest of the logic works as on libmtp.
# See https://bugs.launchpad.net/bugs/2073323
if self.storage_id == self.parent_id:
self.parent_id = 0
self.fs_cache = weakref.ref(fs_cache) self.fs_cache = weakref.ref(fs_cache)
self.deleted = False self.deleted = False