From d6840d6d5558a5cd6b40c9763072e28c28aba7d7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 29 May 2021 09:59:02 +0530 Subject: [PATCH] Revert the change to ignore objects for which EnumObjects() fails Causing crashes elsewhere. Instead retry with a sleep. Also report the object id for the failing object in the error message. --- .../mtp/windows/content_enumeration.cpp | 19 ++++++++++++++----- src/calibre/utils/windows/common.h | 4 ++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/calibre/devices/mtp/windows/content_enumeration.cpp b/src/calibre/devices/mtp/windows/content_enumeration.cpp index f1c7233362..59640d92b2 100644 --- a/src/calibre/devices/mtp/windows/content_enumeration.cpp +++ b/src/calibre/devices/mtp/windows/content_enumeration.cpp @@ -325,7 +325,19 @@ find_objects_in(CComPtr &content, CComPtrEnumObjects(0, parent_id, NULL, &children); Py_END_ALLOW_THREADS; - if (FAILED(hr)) {hresult_set_exc("Failed to get children from device", hr); *enum_failed = true; return false;} + if (FAILED(hr)) { + fwprintf(stderr, L"Failed to EnumObjects() for object id: %s retrying with a sleep.\n", parent_id); fflush(stderr); + Py_BEGIN_ALLOW_THREADS; + Sleep(500); + hr = content->EnumObjects(0, parent_id, NULL, &children); + Py_END_ALLOW_THREADS; + if (FAILED(hr)) { + pyobject_raii parent_name(PyUnicode_FromWideChar(parent_id, -1)); + set_error_from_hresult(wpd::WPDError, __FILE__, __LINE__, hr, "Failed to EnumObjects() of folder from device", parent_name.ptr()); + *enum_failed = true; + return false; + } + } *enum_failed = false; hr = S_OK; @@ -452,10 +464,7 @@ get_files_and_folders(unsigned int level, IPortableDevice *device, CComPtr