Show More
@@ -1268,6 +1268,84 b' bail:' | |||||
1268 | PyMem_Free(name); |
|
1268 | PyMem_Free(name); | |
1269 | return file_obj; |
|
1269 | return file_obj; | |
1270 | } |
|
1270 | } | |
|
1271 | ||||
|
1272 | static PyObject *getfstype(PyObject *self, PyObject *args) | |||
|
1273 | /* given a directory path, return filesystem type name (best-effort) */ | |||
|
1274 | { | |||
|
1275 | const char *path = NULL; | |||
|
1276 | char *fullpath = NULL; | |||
|
1277 | char *volume = NULL; | |||
|
1278 | DWORD size = 0; | |||
|
1279 | char fstype[MAX_PATH + 1]; | |||
|
1280 | ||||
|
1281 | if (!PyArg_ParseTuple(args, "s", &path)) | |||
|
1282 | return NULL; | |||
|
1283 | ||||
|
1284 | size = GetFullPathName(path, 0, NULL, NULL); | |||
|
1285 | ||||
|
1286 | if (size == 0) { | |||
|
1287 | PyErr_SetFromWindowsErrWithFilename(GetLastError(), path); | |||
|
1288 | return NULL; | |||
|
1289 | } | |||
|
1290 | ||||
|
1291 | fullpath = calloc(size, sizeof(fullpath[0])); | |||
|
1292 | volume = calloc(size, sizeof(volume[0])); | |||
|
1293 | ||||
|
1294 | if (!fullpath || !volume) { | |||
|
1295 | PyErr_SetString(PyExc_MemoryError, "out of memory"); | |||
|
1296 | goto bail; | |||
|
1297 | } | |||
|
1298 | ||||
|
1299 | if (!GetFullPathName(path, size, fullpath, NULL)) { | |||
|
1300 | PyErr_SetFromWindowsErrWithFilename(GetLastError(), path); | |||
|
1301 | goto bail; | |||
|
1302 | } | |||
|
1303 | ||||
|
1304 | if (!GetVolumePathName(fullpath, volume, size)) { | |||
|
1305 | PyErr_SetFromWindowsErrWithFilename(GetLastError(), path); | |||
|
1306 | goto bail; | |||
|
1307 | } | |||
|
1308 | ||||
|
1309 | /* Even though the documentation says SMB doesn't support volume management | |||
|
1310 | * functions, passing an SMB path to GetVolumeInformation() returns 'NTFS'. | |||
|
1311 | * So bail unless this is known to _not_ be a network drive. */ | |||
|
1312 | switch (GetDriveType(volume)) { | |||
|
1313 | case DRIVE_FIXED: | |||
|
1314 | case DRIVE_REMOVABLE: | |||
|
1315 | case DRIVE_CDROM: | |||
|
1316 | case DRIVE_RAMDISK: | |||
|
1317 | break; | |||
|
1318 | ||||
|
1319 | case DRIVE_REMOTE: | |||
|
1320 | free(fullpath); | |||
|
1321 | free(volume); | |||
|
1322 | return Py_BuildValue("s", "cifs"); | |||
|
1323 | ||||
|
1324 | case DRIVE_UNKNOWN: | |||
|
1325 | case DRIVE_NO_ROOT_DIR: | |||
|
1326 | default: | |||
|
1327 | free(fullpath); | |||
|
1328 | free(volume); | |||
|
1329 | Py_RETURN_NONE; | |||
|
1330 | } | |||
|
1331 | ||||
|
1332 | if (!GetVolumeInformation(volume, NULL, 0, NULL, NULL, NULL, fstype, | |||
|
1333 | sizeof(fstype))) { | |||
|
1334 | PyErr_SetFromWindowsErrWithFilename(GetLastError(), volume); | |||
|
1335 | goto bail; | |||
|
1336 | } | |||
|
1337 | ||||
|
1338 | free(fullpath); | |||
|
1339 | free(volume); | |||
|
1340 | return Py_BuildValue("s", fstype); | |||
|
1341 | ||||
|
1342 | bail: | |||
|
1343 | if (fullpath) | |||
|
1344 | free(fullpath); | |||
|
1345 | if (volume) | |||
|
1346 | free(volume); | |||
|
1347 | return NULL; | |||
|
1348 | } | |||
1271 | #endif |
|
1349 | #endif | |
1272 |
|
1350 | |||
1273 | #ifdef __APPLE__ |
|
1351 | #ifdef __APPLE__ | |
@@ -1307,13 +1385,13 b' static PyMethodDef methods[] = {' | |||||
1307 | {"setprocname", (PyCFunction)setprocname, METH_VARARGS, |
|
1385 | {"setprocname", (PyCFunction)setprocname, METH_VARARGS, | |
1308 | "set process title (best-effort)\n"}, |
|
1386 | "set process title (best-effort)\n"}, | |
1309 | #endif |
|
1387 | #endif | |
1310 | #if defined(HAVE_BSD_STATFS) || defined(HAVE_LINUX_STATFS) |
|
1388 | {"unblocksignal", (PyCFunction)unblocksignal, METH_VARARGS, | |
|
1389 | "change signal mask to unblock a given signal\n"}, | |||
|
1390 | #endif /* ndef _WIN32 */ | |||
|
1391 | #if defined(HAVE_BSD_STATFS) || defined(HAVE_LINUX_STATFS) || defined(_WIN32) | |||
1311 | {"getfstype", (PyCFunction)getfstype, METH_VARARGS, |
|
1392 | {"getfstype", (PyCFunction)getfstype, METH_VARARGS, | |
1312 | "get filesystem type (best-effort)\n"}, |
|
1393 | "get filesystem type (best-effort)\n"}, | |
1313 | #endif |
|
1394 | #endif | |
1314 | {"unblocksignal", (PyCFunction)unblocksignal, METH_VARARGS, |
|
|||
1315 | "change signal mask to unblock a given signal\n"}, |
|
|||
1316 | #endif /* ndef _WIN32 */ |
|
|||
1317 | #ifdef __APPLE__ |
|
1395 | #ifdef __APPLE__ | |
1318 | { |
|
1396 | { | |
1319 | "isgui", (PyCFunction)isgui, METH_NOARGS, |
|
1397 | "isgui", (PyCFunction)isgui, METH_NOARGS, | |
@@ -1323,7 +1401,7 b' static PyMethodDef methods[] = {' | |||||
1323 | {NULL, NULL} |
|
1401 | {NULL, NULL} | |
1324 | }; |
|
1402 | }; | |
1325 |
|
1403 | |||
1326 |
static const int version = |
|
1404 | static const int version = 3; | |
1327 |
|
1405 | |||
1328 | #ifdef IS_PY3K |
|
1406 | #ifdef IS_PY3K | |
1329 | static struct PyModuleDef osutil_module = { |
|
1407 | static struct PyModuleDef osutil_module = { |
@@ -74,7 +74,7 b' def _importfrom(pkgname, modname):' | |||||
74 | (r'cext', r'bdiff'): 1, |
|
74 | (r'cext', r'bdiff'): 1, | |
75 | (r'cext', r'diffhelpers'): 1, |
|
75 | (r'cext', r'diffhelpers'): 1, | |
76 | (r'cext', r'mpatch'): 1, |
|
76 | (r'cext', r'mpatch'): 1, | |
77 |
(r'cext', r'osutil'): |
|
77 | (r'cext', r'osutil'): 3, | |
78 | (r'cext', r'parsers'): 4, |
|
78 | (r'cext', r'parsers'): 4, | |
79 | } |
|
79 | } | |
80 |
|
80 |
General Comments 0
You need to be logged in to leave comments.
Login now