diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index f7ba01e0f9..10135eaeab 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -408,7 +408,7 @@ class KOBO(USBMS): # Remove books that are no longer in the filesystem. Cache contains # indices into the booklist if book not in filesystem, None otherwise # Do the operation in reverse order so indices remain valid - for idx in sorted(itervalues(bl_cache), reverse=True): + for idx in sorted(itervalues(bl_cache), reverse=True, key=lambda x: x or -1): if idx is not None: need_sync = True del bl[idx] @@ -1971,7 +1971,7 @@ class KOBOTOUCH(KOBO): # Remove books that are no longer in the filesystem. Cache contains # indices into the booklist if book not in filesystem, None otherwise # Do the operation in reverse order so indices remain valid - for idx in sorted(itervalues(bl_cache), reverse=True): + for idx in sorted(itervalues(bl_cache), reverse=True, key=lambda x: x or -1): if idx is not None: if not os.path.exists(self.normalize_path(os.path.join(prefix, bl[idx].lpath))) or not bl[idx].contentID: need_sync = True