From 75d111e3f639561f23603f594a8ff35d4abb646a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 18 Jul 2024 15:15:00 +0530 Subject: [PATCH] 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) --- src/calibre/devices/mtp/filesystem_cache.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/calibre/devices/mtp/filesystem_cache.py b/src/calibre/devices/mtp/filesystem_cache.py index 581e07d7e2..c5f6c8a921 100644 --- a/src/calibre/devices/mtp/filesystem_cache.py +++ b/src/calibre/devices/mtp/filesystem_cache.py @@ -16,6 +16,7 @@ from operator import attrgetter from typing import Dict, Tuple from calibre import force_unicode, human_readable, prints +from calibre.constants import iswindows from calibre.ebooks import BOOK_EXTENSIONS from calibre.utils.date import as_utc, local_tz from calibre.utils.icu import lower, sort_key @@ -75,9 +76,15 @@ class FileOrFolder: self.files = [] self.folders = [] 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 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.deleted = False