Mercurial > public > mercurial-scm > hg
comparison mercurial/win32.py @ 35512:5cc1becd0493
win32: split a utility function to obtain the volume out of getfstype()
This is only done on Windows because it's simple enough to call statfs() on
Unix. The goal is to display this in `hg debugfs`.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 29 Dec 2017 22:15:37 -0500 |
parents | 2062f7c2ac83 |
children | 94a127152e25 |
comparison
equal
deleted
inserted
replaced
35511:d8f408d999f9 | 35512:5cc1becd0493 |
---|---|
426 raise ctypes.WinError() # Note: WinError is a function | 426 raise ctypes.WinError() # Note: WinError is a function |
427 elif len == size: | 427 elif len == size: |
428 raise ctypes.WinError(_ERROR_INSUFFICIENT_BUFFER) | 428 raise ctypes.WinError(_ERROR_INSUFFICIENT_BUFFER) |
429 return buf.value | 429 return buf.value |
430 | 430 |
431 def getfstype(path): | 431 def getvolumename(path): |
432 """Get the filesystem type name from a directory or file (best-effort) | 432 """Get the mount point of the filesystem from a directory or file |
433 (best-effort) | |
433 | 434 |
434 Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc. | 435 Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc. |
435 """ | 436 """ |
436 # realpath() calls GetFullPathName() | 437 # realpath() calls GetFullPathName() |
437 realpath = os.path.realpath(path) | 438 realpath = os.path.realpath(path) |
440 buf = ctypes.create_string_buffer(size) | 441 buf = ctypes.create_string_buffer(size) |
441 | 442 |
442 if not _kernel32.GetVolumePathNameA(realpath, ctypes.byref(buf), size): | 443 if not _kernel32.GetVolumePathNameA(realpath, ctypes.byref(buf), size): |
443 raise ctypes.WinError() # Note: WinError is a function | 444 raise ctypes.WinError() # Note: WinError is a function |
444 | 445 |
445 t = _kernel32.GetDriveTypeA(buf.value) | 446 return buf.value |
447 | |
448 def getfstype(path): | |
449 """Get the filesystem type name from a directory or file (best-effort) | |
450 | |
451 Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc. | |
452 """ | |
453 volume = getvolumename(path) | |
454 | |
455 t = _kernel32.GetDriveTypeA(volume) | |
446 | 456 |
447 if t == _DRIVE_REMOTE: | 457 if t == _DRIVE_REMOTE: |
448 return 'cifs' | 458 return 'cifs' |
449 elif t not in (_DRIVE_REMOVABLE, _DRIVE_FIXED, _DRIVE_CDROM, | 459 elif t not in (_DRIVE_REMOVABLE, _DRIVE_FIXED, _DRIVE_CDROM, |
450 _DRIVE_RAMDISK): | 460 _DRIVE_RAMDISK): |
451 return None | 461 return None |
452 | 462 |
453 size = 256 | 463 size = 256 |
454 name = ctypes.create_string_buffer(size) | 464 name = ctypes.create_string_buffer(size) |
455 | 465 |
456 if not _kernel32.GetVolumeInformationA(buf.value, None, 0, None, None, None, | 466 if not _kernel32.GetVolumeInformationA(volume, None, 0, None, None, None, |
457 ctypes.byref(name), size): | 467 ctypes.byref(name), size): |
458 raise ctypes.WinError() # Note: WinError is a function | 468 raise ctypes.WinError() # Note: WinError is a function |
459 | 469 |
460 return name.value | 470 return name.value |
461 | 471 |