mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Windows: Fix a long standing bug in the device eject code that for some reason only manifested in 0.9.5. Fixes #1075782 (Device | Eject not ejecting device)
This commit is contained in:
parent
d5b714821e
commit
0b25ffee6c
@ -901,8 +901,11 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
for d in drives:
|
for d in drives:
|
||||||
try:
|
try:
|
||||||
winutil.eject_drive(bytes(d)[0])
|
winutil.eject_drive(bytes(d)[0])
|
||||||
except:
|
except Exception as e:
|
||||||
pass
|
try:
|
||||||
|
prints(as_unicode(e))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
t = Thread(target=do_it, args=[drives])
|
t = Thread(target=do_it, args=[drives])
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
|
@ -467,11 +467,11 @@ eject_drive_letter(WCHAR DriveLetter) {
|
|||||||
|
|
||||||
DeviceNumber = -1;
|
DeviceNumber = -1;
|
||||||
|
|
||||||
hVolume = CreateFile(szVolumeAccessPath, 0,
|
hVolume = CreateFileW(szVolumeAccessPath, 0,
|
||||||
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||||
NULL, OPEN_EXISTING, 0, NULL);
|
NULL, OPEN_EXISTING, 0, NULL);
|
||||||
if (hVolume == INVALID_HANDLE_VALUE) {
|
if (hVolume == INVALID_HANDLE_VALUE) {
|
||||||
PyErr_SetString(PyExc_ValueError, "Invalid handle value for drive letter");
|
PyErr_SetFromWindowsErr(0);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,11 +529,17 @@ eject_drive_letter(WCHAR DriveLetter) {
|
|||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
winutil_eject_drive(PyObject *self, PyObject *args) {
|
winutil_eject_drive(PyObject *self, PyObject *args) {
|
||||||
char DriveLetter;
|
char letter = '0';
|
||||||
|
WCHAR DriveLetter = L'0';
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "c", &DriveLetter)) return NULL;
|
if (!PyArg_ParseTuple(args, "c", &letter)) return NULL;
|
||||||
|
|
||||||
if (!eject_drive_letter((WCHAR)DriveLetter)) return NULL;
|
if (mbtowc(&DriveLetter, &letter, 1) == -1) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "Failed to convert drive letter to wchar");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!eject_drive_letter(DriveLetter)) return NULL;
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user