mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Increase batch size of Next() calls in inner loop
Also fail with an error for any return value of Next() other than S_OK and S_FALSE.
This commit is contained in:
parent
614b58c3b6
commit
b293089ba3
@ -332,7 +332,7 @@ find_objects_in(CComPtr<IPortableDeviceContent> &content, CComPtr<IPortableDevic
|
|||||||
Py_END_ALLOW_THREADS;
|
Py_END_ALLOW_THREADS;
|
||||||
|
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
fwprintf(stderr, L"Failed to EnumObjects() for object id: %s retrying with a sleep.\n", parent_id); fflush(stderr);
|
fwprintf(stderr, L"Failed to EnumObjects() for object id: %s with hr: %x retrying with a sleep.\n", parent_id, hr); fflush(stderr);
|
||||||
Py_BEGIN_ALLOW_THREADS;
|
Py_BEGIN_ALLOW_THREADS;
|
||||||
Sleep(500);
|
Sleep(500);
|
||||||
hr = content->EnumObjects(0, parent_id, NULL, &children);
|
hr = content->EnumObjects(0, parent_id, NULL, &children);
|
||||||
@ -345,22 +345,29 @@ find_objects_in(CComPtr<IPortableDeviceContent> &content, CComPtr<IPortableDevic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = S_OK;
|
wchar_t* child_ids[64];
|
||||||
|
prop_variant pv(VT_LPWSTR);
|
||||||
while (hr == S_OK) {
|
DWORD fetched;
|
||||||
DWORD fetched;
|
while (true) {
|
||||||
prop_variant pv(VT_LPWSTR);
|
|
||||||
generic_raii_array<wchar_t*, co_task_mem_free, 16> child_ids;
|
|
||||||
Py_BEGIN_ALLOW_THREADS;
|
Py_BEGIN_ALLOW_THREADS;
|
||||||
hr = children->Next((ULONG)child_ids.size(), child_ids.ptr(), &fetched);
|
hr = children->Next(64u, child_ids, &fetched);
|
||||||
Py_END_ALLOW_THREADS;
|
Py_END_ALLOW_THREADS;
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr) && fetched) {
|
||||||
for (DWORD i = 0; i < fetched; i++) {
|
for (DWORD i = 0; i < fetched; i++) {
|
||||||
pv.pwszVal = child_ids[i];
|
pv.pwszVal = child_ids[i];
|
||||||
hr2 = object_ids->Add(&pv);
|
hr2 = object_ids->Add(&pv);
|
||||||
pv.pwszVal = NULL;
|
pv.pwszVal = NULL;
|
||||||
if (FAILED(hr2)) { hresult_set_exc("Failed to add child ids to propvariantcollection", hr2); return false; }
|
CoTaskMemFree(child_ids[i]); child_ids[i] = NULL;
|
||||||
|
if (FAILED(hr2)) {
|
||||||
|
for (DWORD c = i + 1; c < fetched; c++) CoTaskMemFree(child_ids[c]);
|
||||||
|
hresult_set_exc("Failed to add child id to propvariantcollection", hr2); return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (hr == S_FALSE && !fetched) break;
|
||||||
|
pyobject_raii parent_name(PyUnicode_FromWideChar(parent_id, -1));
|
||||||
|
set_error_from_hresult(wpd::WPDError, __FILE__, __LINE__, hr, "Failed to EnumObjects()->Next() of folder from device", parent_name.ptr());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user