Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/win32.py @ 35514:2062f7c2ac83
win32: implement util.getfstype()
This will allow NTFS to be added to the hardlink whitelist, and resume creating
hardlinks in transactions (which was disabled globally in 07a92bbd02e5; see also
e5ce49a30146). I opted to report "cifs" for remote volumes because this shows
in `hg debugfs`, which also reports that hardlinks are supported for these
volumes. So being able to distinguish it from "unknown" seems useful.
The documentation [1] seems to indicate that SMB isn't supported by these
functions, but experimenting shows that mapped drives are reported as "NTFS" on
Windows 7. I don't have a second Windows machine, but instead shared a temp
directory on C:\. In this setup, both of the following were detected as 'cifs'
with the explicit GetDriveType() check:
Z:\repo>hg ci -A
C:\>hg -R \\hostname\temp\repo ci -A # (without Z:\ being mapped)
It looks like this is called 6 times to add and commit a single new file, so I'm
a little surprised this isn't cached.
[1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Fri, 29 Dec 2017 21:28:19 -0500 |
parents | d5b2beca16c0 |
children | 5cc1becd0493 |
rev | line source |
---|---|
8226
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
1 # win32.py - utility functions that use win32 API |
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
2 # |
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others |
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
4 # |
8b2cd04a6e97
put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
8227
0a9542703300
turn some comments back into module docstrings
Martin Geisler <mg@lazybytes.net>
parents:
8226
diff
changeset
|
7 |
25994
d6beeb618700
win32: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
8 from __future__ import absolute_import |
d6beeb618700
win32: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
9 |
d6beeb618700
win32: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
10 import ctypes |
d6beeb618700
win32: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
11 import errno |
d6beeb618700
win32: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
12 import msvcrt |
d6beeb618700
win32: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
13 import os |
d6beeb618700
win32: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
14 import random |
d6beeb618700
win32: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25660
diff
changeset
|
15 import subprocess |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
16 |
30670
5861bdbeb9a3
py3: use pycompat.getcwd instead of os.getcwd
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30642
diff
changeset
|
17 from . import ( |
5861bdbeb9a3
py3: use pycompat.getcwd instead of os.getcwd
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30642
diff
changeset
|
18 encoding, |
5861bdbeb9a3
py3: use pycompat.getcwd instead of os.getcwd
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30642
diff
changeset
|
19 pycompat, |
5861bdbeb9a3
py3: use pycompat.getcwd instead of os.getcwd
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30642
diff
changeset
|
20 ) |
30642
344e68882cd3
py3: replace os.environ with encoding.environ (part 4 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30327
diff
changeset
|
21 |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
22 _kernel32 = ctypes.windll.kernel32 |
14345
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
23 _advapi32 = ctypes.windll.advapi32 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
24 _user32 = ctypes.windll.user32 |
33492
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
25 _crypt32 = ctypes.windll.crypt32 |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
26 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
27 _BOOL = ctypes.c_long |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
28 _WORD = ctypes.c_ushort |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
29 _DWORD = ctypes.c_ulong |
14345
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
30 _UINT = ctypes.c_uint |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
31 _LONG = ctypes.c_long |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
32 _LPCSTR = _LPSTR = ctypes.c_char_p |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
33 _HANDLE = ctypes.c_void_p |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
34 _HWND = _HANDLE |
33492
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
35 _PCCERT_CONTEXT = ctypes.c_void_p |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
36 |
14345
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
37 _INVALID_HANDLE_VALUE = _HANDLE(-1).value |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
38 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
39 # GetLastError |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
40 _ERROR_SUCCESS = 0 |
21193
07f9825865de
win32: add missing definition of _ERROR_NO_MORE_FILES caught by pyflakes
Yuya Nishihara <yuya@tcha.org>
parents:
20528
diff
changeset
|
41 _ERROR_NO_MORE_FILES = 18 |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
42 _ERROR_INVALID_PARAMETER = 87 |
24652
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
43 _ERROR_BROKEN_PIPE = 109 |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
44 _ERROR_INSUFFICIENT_BUFFER = 122 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
45 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
46 # WPARAM is defined as UINT_PTR (unsigned type) |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
47 # LPARAM is defined as LONG_PTR (signed type) |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
48 if ctypes.sizeof(ctypes.c_long) == ctypes.sizeof(ctypes.c_void_p): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
49 _WPARAM = ctypes.c_ulong |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
50 _LPARAM = ctypes.c_long |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
51 elif ctypes.sizeof(ctypes.c_longlong) == ctypes.sizeof(ctypes.c_void_p): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
52 _WPARAM = ctypes.c_ulonglong |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
53 _LPARAM = ctypes.c_longlong |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
54 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
55 class _FILETIME(ctypes.Structure): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
56 _fields_ = [('dwLowDateTime', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
57 ('dwHighDateTime', _DWORD)] |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
58 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
59 class _BY_HANDLE_FILE_INFORMATION(ctypes.Structure): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
60 _fields_ = [('dwFileAttributes', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
61 ('ftCreationTime', _FILETIME), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
62 ('ftLastAccessTime', _FILETIME), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
63 ('ftLastWriteTime', _FILETIME), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
64 ('dwVolumeSerialNumber', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
65 ('nFileSizeHigh', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
66 ('nFileSizeLow', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
67 ('nNumberOfLinks', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
68 ('nFileIndexHigh', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
69 ('nFileIndexLow', _DWORD)] |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
70 |
18959
2f6418d8a4c9
check-code: catch trailing space in comments
Mads Kiilerich <madski@unity3d.com>
parents:
18175
diff
changeset
|
71 # CreateFile |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
72 _FILE_SHARE_READ = 0x00000001 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
73 _FILE_SHARE_WRITE = 0x00000002 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
74 _FILE_SHARE_DELETE = 0x00000004 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
75 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
76 _OPEN_EXISTING = 3 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
77 |
17006
6fc7fd72ba3e
win32.py: let samefile and samedevice work on directories too
Adrian Buehlmann <adrian@cadifra.com>
parents:
16807
diff
changeset
|
78 _FILE_FLAG_BACKUP_SEMANTICS = 0x02000000 |
6fc7fd72ba3e
win32.py: let samefile and samedevice work on directories too
Adrian Buehlmann <adrian@cadifra.com>
parents:
16807
diff
changeset
|
79 |
13776
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
80 # SetFileAttributes |
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
81 _FILE_ATTRIBUTE_NORMAL = 0x80 |
13795
43b5fe18ea6c
set NOT_CONTENT_INDEXED on .hg dir (issue2694)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13776
diff
changeset
|
82 _FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x2000 |
13776
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
83 |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
84 # Process Security and Access Rights |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
85 _PROCESS_QUERY_INFORMATION = 0x0400 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
86 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
87 # GetExitCodeProcess |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
88 _STILL_ACTIVE = 259 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
89 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
90 class _STARTUPINFO(ctypes.Structure): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
91 _fields_ = [('cb', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
92 ('lpReserved', _LPSTR), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
93 ('lpDesktop', _LPSTR), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
94 ('lpTitle', _LPSTR), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
95 ('dwX', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
96 ('dwY', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
97 ('dwXSize', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
98 ('dwYSize', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
99 ('dwXCountChars', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
100 ('dwYCountChars', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
101 ('dwFillAttribute', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
102 ('dwFlags', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
103 ('wShowWindow', _WORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
104 ('cbReserved2', _WORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
105 ('lpReserved2', ctypes.c_char_p), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
106 ('hStdInput', _HANDLE), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
107 ('hStdOutput', _HANDLE), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
108 ('hStdError', _HANDLE)] |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
109 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
110 class _PROCESS_INFORMATION(ctypes.Structure): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
111 _fields_ = [('hProcess', _HANDLE), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
112 ('hThread', _HANDLE), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
113 ('dwProcessId', _DWORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
114 ('dwThreadId', _DWORD)] |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
115 |
17050
e780fb37168b
win32: specify _CREATE_NO_WINDOW on spawndetached()
Adrian Buehlmann <adrian@cadifra.com>
parents:
17006
diff
changeset
|
116 _CREATE_NO_WINDOW = 0x08000000 |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
117 _SW_HIDE = 0 |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
118 |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
119 class _COORD(ctypes.Structure): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
120 _fields_ = [('X', ctypes.c_short), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
121 ('Y', ctypes.c_short)] |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
122 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
123 class _SMALL_RECT(ctypes.Structure): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
124 _fields_ = [('Left', ctypes.c_short), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
125 ('Top', ctypes.c_short), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
126 ('Right', ctypes.c_short), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
127 ('Bottom', ctypes.c_short)] |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
128 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
129 class _CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
130 _fields_ = [('dwSize', _COORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
131 ('dwCursorPosition', _COORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
132 ('wAttributes', _WORD), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
133 ('srWindow', _SMALL_RECT), |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
134 ('dwMaximumWindowSize', _COORD)] |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
135 |
32684
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
136 _STD_OUTPUT_HANDLE = _DWORD(-11).value |
14344
e1db8a00188b
win32.py: more explicit definition of _STD_ERROR_HANDLE
Adrian Buehlmann <adrian@cadifra.com>
parents:
14237
diff
changeset
|
137 _STD_ERROR_HANDLE = _DWORD(-12).value |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
138 |
33492
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
139 # CERT_TRUST_STATUS dwErrorStatus |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
140 CERT_TRUST_IS_PARTIAL_CHAIN = 0x10000 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
141 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
142 # CertCreateCertificateContext encodings |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
143 X509_ASN_ENCODING = 0x00000001 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
144 PKCS_7_ASN_ENCODING = 0x00010000 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
145 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
146 # These structs are only complete enough to achieve what we need. |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
147 class CERT_CHAIN_CONTEXT(ctypes.Structure): |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
148 _fields_ = ( |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
149 ("cbSize", _DWORD), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
150 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
151 # CERT_TRUST_STATUS struct |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
152 ("dwErrorStatus", _DWORD), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
153 ("dwInfoStatus", _DWORD), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
154 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
155 ("cChain", _DWORD), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
156 ("rgpChain", ctypes.c_void_p), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
157 ("cLowerQualityChainContext", _DWORD), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
158 ("rgpLowerQualityChainContext", ctypes.c_void_p), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
159 ("fHasRevocationFreshnessTime", _BOOL), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
160 ("dwRevocationFreshnessTime", _DWORD), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
161 ) |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
162 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
163 class CERT_USAGE_MATCH(ctypes.Structure): |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
164 _fields_ = ( |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
165 ("dwType", _DWORD), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
166 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
167 # CERT_ENHKEY_USAGE struct |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
168 ("cUsageIdentifier", _DWORD), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
169 ("rgpszUsageIdentifier", ctypes.c_void_p), # LPSTR * |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
170 ) |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
171 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
172 class CERT_CHAIN_PARA(ctypes.Structure): |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
173 _fields_ = ( |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
174 ("cbSize", _DWORD), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
175 ("RequestedUsage", CERT_USAGE_MATCH), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
176 ("RequestedIssuancePolicy", CERT_USAGE_MATCH), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
177 ("dwUrlRetrievalTimeout", _DWORD), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
178 ("fCheckRevocationFreshnessTime", _BOOL), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
179 ("dwRevocationFreshnessTime", _DWORD), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
180 ("pftCacheResync", ctypes.c_void_p), # LPFILETIME |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
181 ("pStrongSignPara", ctypes.c_void_p), # PCCERT_STRONG_SIGN_PARA |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
182 ("dwStrongSignFlags", _DWORD), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
183 ) |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
184 |
14345
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
185 # types of parameters of C functions used (required by pypy) |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
186 |
33492
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
187 _crypt32.CertCreateCertificateContext.argtypes = [_DWORD, # cert encoding |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
188 ctypes.c_char_p, # cert |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
189 _DWORD] # cert size |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
190 _crypt32.CertCreateCertificateContext.restype = _PCCERT_CONTEXT |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
191 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
192 _crypt32.CertGetCertificateChain.argtypes = [ |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
193 ctypes.c_void_p, # HCERTCHAINENGINE |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
194 _PCCERT_CONTEXT, |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
195 ctypes.c_void_p, # LPFILETIME |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
196 ctypes.c_void_p, # HCERTSTORE |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
197 ctypes.c_void_p, # PCERT_CHAIN_PARA |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
198 _DWORD, |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
199 ctypes.c_void_p, # LPVOID |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
200 ctypes.c_void_p # PCCERT_CHAIN_CONTEXT * |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
201 ] |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
202 _crypt32.CertGetCertificateChain.restype = _BOOL |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
203 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
204 _crypt32.CertFreeCertificateContext.argtypes = [_PCCERT_CONTEXT] |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
205 _crypt32.CertFreeCertificateContext.restype = _BOOL |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
206 |
14345
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
207 _kernel32.CreateFileA.argtypes = [_LPCSTR, _DWORD, _DWORD, ctypes.c_void_p, |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
208 _DWORD, _DWORD, _HANDLE] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
209 _kernel32.CreateFileA.restype = _HANDLE |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
210 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
211 _kernel32.GetFileInformationByHandle.argtypes = [_HANDLE, ctypes.c_void_p] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
212 _kernel32.GetFileInformationByHandle.restype = _BOOL |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
213 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
214 _kernel32.CloseHandle.argtypes = [_HANDLE] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
215 _kernel32.CloseHandle.restype = _BOOL |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
216 |
15095
ec222a29bdf0
win32: quietly ignore missing CreateHardLinkA for Wine
Matt Mackall <mpm@selenic.com>
parents:
14345
diff
changeset
|
217 try: |
ec222a29bdf0
win32: quietly ignore missing CreateHardLinkA for Wine
Matt Mackall <mpm@selenic.com>
parents:
14345
diff
changeset
|
218 _kernel32.CreateHardLinkA.argtypes = [_LPCSTR, _LPCSTR, ctypes.c_void_p] |
ec222a29bdf0
win32: quietly ignore missing CreateHardLinkA for Wine
Matt Mackall <mpm@selenic.com>
parents:
14345
diff
changeset
|
219 _kernel32.CreateHardLinkA.restype = _BOOL |
ec222a29bdf0
win32: quietly ignore missing CreateHardLinkA for Wine
Matt Mackall <mpm@selenic.com>
parents:
14345
diff
changeset
|
220 except AttributeError: |
ec222a29bdf0
win32: quietly ignore missing CreateHardLinkA for Wine
Matt Mackall <mpm@selenic.com>
parents:
14345
diff
changeset
|
221 pass |
14345
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
222 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
223 _kernel32.SetFileAttributesA.argtypes = [_LPCSTR, _DWORD] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
224 _kernel32.SetFileAttributesA.restype = _BOOL |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
225 |
35514
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
226 _DRIVE_UNKNOWN = 0 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
227 _DRIVE_NO_ROOT_DIR = 1 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
228 _DRIVE_REMOVABLE = 2 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
229 _DRIVE_FIXED = 3 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
230 _DRIVE_REMOTE = 4 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
231 _DRIVE_CDROM = 5 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
232 _DRIVE_RAMDISK = 6 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
233 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
234 _kernel32.GetDriveTypeA.argtypes = [_LPCSTR] |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
235 _kernel32.GetDriveTypeA.restype = _UINT |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
236 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
237 _kernel32.GetVolumeInformationA.argtypes = [_LPCSTR, ctypes.c_void_p, _DWORD, |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
238 ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, _DWORD] |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
239 _kernel32.GetVolumeInformationA.restype = _BOOL |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
240 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
241 _kernel32.GetVolumePathNameA.argtypes = [_LPCSTR, ctypes.c_void_p, _DWORD] |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
242 _kernel32.GetVolumePathNameA.restype = _BOOL |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
243 |
14345
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
244 _kernel32.OpenProcess.argtypes = [_DWORD, _BOOL, _DWORD] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
245 _kernel32.OpenProcess.restype = _HANDLE |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
246 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
247 _kernel32.GetExitCodeProcess.argtypes = [_HANDLE, ctypes.c_void_p] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
248 _kernel32.GetExitCodeProcess.restype = _BOOL |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
249 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
250 _kernel32.GetLastError.argtypes = [] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
251 _kernel32.GetLastError.restype = _DWORD |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
252 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
253 _kernel32.GetModuleFileNameA.argtypes = [_HANDLE, ctypes.c_void_p, _DWORD] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
254 _kernel32.GetModuleFileNameA.restype = _DWORD |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
255 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
256 _kernel32.CreateProcessA.argtypes = [_LPCSTR, _LPCSTR, ctypes.c_void_p, |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
257 ctypes.c_void_p, _BOOL, _DWORD, ctypes.c_void_p, _LPCSTR, ctypes.c_void_p, |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
258 ctypes.c_void_p] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
259 _kernel32.CreateProcessA.restype = _BOOL |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
260 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
261 _kernel32.ExitProcess.argtypes = [_UINT] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
262 _kernel32.ExitProcess.restype = None |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
263 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
264 _kernel32.GetCurrentProcessId.argtypes = [] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
265 _kernel32.GetCurrentProcessId.restype = _DWORD |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
266 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
267 _SIGNAL_HANDLER = ctypes.WINFUNCTYPE(_BOOL, _DWORD) |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
268 _kernel32.SetConsoleCtrlHandler.argtypes = [_SIGNAL_HANDLER, _BOOL] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
269 _kernel32.SetConsoleCtrlHandler.restype = _BOOL |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
270 |
32684
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
271 _kernel32.SetConsoleMode.argtypes = [_HANDLE, _DWORD] |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
272 _kernel32.SetConsoleMode.restype = _BOOL |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
273 |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
274 _kernel32.GetConsoleMode.argtypes = [_HANDLE, ctypes.c_void_p] |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
275 _kernel32.GetConsoleMode.restype = _BOOL |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
276 |
14345
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
277 _kernel32.GetStdHandle.argtypes = [_DWORD] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
278 _kernel32.GetStdHandle.restype = _HANDLE |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
279 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
280 _kernel32.GetConsoleScreenBufferInfo.argtypes = [_HANDLE, ctypes.c_void_p] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
281 _kernel32.GetConsoleScreenBufferInfo.restype = _BOOL |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
282 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
283 _advapi32.GetUserNameA.argtypes = [ctypes.c_void_p, ctypes.c_void_p] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
284 _advapi32.GetUserNameA.restype = _BOOL |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
285 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
286 _user32.GetWindowThreadProcessId.argtypes = [_HANDLE, ctypes.c_void_p] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
287 _user32.GetWindowThreadProcessId.restype = _DWORD |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
288 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
289 _user32.ShowWindow.argtypes = [_HANDLE, ctypes.c_int] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
290 _user32.ShowWindow.restype = _BOOL |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
291 |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
292 _WNDENUMPROC = ctypes.WINFUNCTYPE(_BOOL, _HWND, _LPARAM) |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
293 _user32.EnumWindows.argtypes = [_WNDENUMPROC, _LPARAM] |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
294 _user32.EnumWindows.restype = _BOOL |
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
295 |
24652
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
296 _kernel32.PeekNamedPipe.argtypes = [_HANDLE, ctypes.c_void_p, _DWORD, |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
297 ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p] |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
298 _kernel32.PeekNamedPipe.restype = _BOOL |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
299 |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
300 def _raiseoserror(name): |
33419
7c33adc823e0
win32: work around a WinError problem handling HRESULT types
Matt Harbison <matt_harbison@yahoo.com>
parents:
32696
diff
changeset
|
301 # Force the code to a signed int to avoid an 'int too large' error. |
7c33adc823e0
win32: work around a WinError problem handling HRESULT types
Matt Harbison <matt_harbison@yahoo.com>
parents:
32696
diff
changeset
|
302 # See https://bugs.python.org/issue28474 |
7c33adc823e0
win32: work around a WinError problem handling HRESULT types
Matt Harbison <matt_harbison@yahoo.com>
parents:
32696
diff
changeset
|
303 code = _kernel32.GetLastError() |
7c33adc823e0
win32: work around a WinError problem handling HRESULT types
Matt Harbison <matt_harbison@yahoo.com>
parents:
32696
diff
changeset
|
304 if code > 0x7fffffff: |
7c33adc823e0
win32: work around a WinError problem handling HRESULT types
Matt Harbison <matt_harbison@yahoo.com>
parents:
32696
diff
changeset
|
305 code -= 2**32 |
7c33adc823e0
win32: work around a WinError problem handling HRESULT types
Matt Harbison <matt_harbison@yahoo.com>
parents:
32696
diff
changeset
|
306 err = ctypes.WinError(code=code) |
34040
d5b2beca16c0
python3: wrap all uses of <exception>.strerror with strtolocal
Augie Fackler <raf@durin42.com>
parents:
33492
diff
changeset
|
307 raise OSError(err.errno, '%s: %s' % (name, |
d5b2beca16c0
python3: wrap all uses of <exception>.strerror with strtolocal
Augie Fackler <raf@durin42.com>
parents:
33492
diff
changeset
|
308 encoding.strtolocal(err.strerror))) |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
309 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
310 def _getfileinfo(name): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
311 fh = _kernel32.CreateFileA(name, 0, |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
312 _FILE_SHARE_READ | _FILE_SHARE_WRITE | _FILE_SHARE_DELETE, |
17006
6fc7fd72ba3e
win32.py: let samefile and samedevice work on directories too
Adrian Buehlmann <adrian@cadifra.com>
parents:
16807
diff
changeset
|
313 None, _OPEN_EXISTING, _FILE_FLAG_BACKUP_SEMANTICS, None) |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
314 if fh == _INVALID_HANDLE_VALUE: |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
315 _raiseoserror(name) |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
316 try: |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
317 fi = _BY_HANDLE_FILE_INFORMATION() |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
318 if not _kernel32.GetFileInformationByHandle(fh, ctypes.byref(fi)): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
319 _raiseoserror(name) |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
320 return fi |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
321 finally: |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
322 _kernel32.CloseHandle(fh) |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
323 |
33492
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
324 def checkcertificatechain(cert, build=True): |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
325 '''Tests the given certificate to see if there is a complete chain to a |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
326 trusted root certificate. As a side effect, missing certificates are |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
327 downloaded and installed unless ``build=False``. True is returned if a |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
328 chain to a trusted root exists (even if built on the fly), otherwise |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
329 False. NB: A chain to a trusted root does NOT imply that the certificate |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
330 is valid. |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
331 ''' |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
332 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
333 chainctxptr = ctypes.POINTER(CERT_CHAIN_CONTEXT) |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
334 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
335 pchainctx = chainctxptr() |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
336 chainpara = CERT_CHAIN_PARA(cbSize=ctypes.sizeof(CERT_CHAIN_PARA), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
337 RequestedUsage=CERT_USAGE_MATCH()) |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
338 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
339 certctx = _crypt32.CertCreateCertificateContext(X509_ASN_ENCODING, cert, |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
340 len(cert)) |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
341 if certctx is None: |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
342 _raiseoserror('CertCreateCertificateContext') |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
343 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
344 flags = 0 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
345 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
346 if not build: |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
347 flags |= 0x100 # CERT_CHAIN_DISABLE_AUTH_ROOT_AUTO_UPDATE |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
348 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
349 try: |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
350 # Building the certificate chain will update root certs as necessary. |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
351 if not _crypt32.CertGetCertificateChain(None, # hChainEngine |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
352 certctx, # pCertContext |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
353 None, # pTime |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
354 None, # hAdditionalStore |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
355 ctypes.byref(chainpara), |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
356 flags, |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
357 None, # pvReserved |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
358 ctypes.byref(pchainctx)): |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
359 _raiseoserror('CertGetCertificateChain') |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
360 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
361 chainctx = pchainctx.contents |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
362 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
363 return chainctx.dwErrorStatus & CERT_TRUST_IS_PARTIAL_CHAIN == 0 |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
364 finally: |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
365 if pchainctx: |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
366 _crypt32.CertFreeCertificateChain(pchainctx) |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
367 _crypt32.CertFreeCertificateContext(certctx) |
14af04391fb9
win32: add a method to trigger the Crypto API to complete a certificate chain
Matt Harbison <matt_harbison@yahoo.com>
parents:
33419
diff
changeset
|
368 |
14235
b9e1b041744f
rename util.os_link to oslink
Adrian Buehlmann <adrian@cadifra.com>
parents:
14230
diff
changeset
|
369 def oslink(src, dst): |
13976
9ca1ff3d4f8c
win32: Wine doesn't know about hardlinks
Matt Mackall <mpm@selenic.com>
parents:
13795
diff
changeset
|
370 try: |
9ca1ff3d4f8c
win32: Wine doesn't know about hardlinks
Matt Mackall <mpm@selenic.com>
parents:
13795
diff
changeset
|
371 if not _kernel32.CreateHardLinkA(dst, src, None): |
9ca1ff3d4f8c
win32: Wine doesn't know about hardlinks
Matt Mackall <mpm@selenic.com>
parents:
13795
diff
changeset
|
372 _raiseoserror(src) |
9ca1ff3d4f8c
win32: Wine doesn't know about hardlinks
Matt Mackall <mpm@selenic.com>
parents:
13795
diff
changeset
|
373 except AttributeError: # Wine doesn't support this function |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
374 _raiseoserror(src) |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
375 |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
376 def nlinks(name): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
377 '''return number of hardlinks for the given file''' |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
378 return _getfileinfo(name).nNumberOfLinks |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
379 |
17006
6fc7fd72ba3e
win32.py: let samefile and samedevice work on directories too
Adrian Buehlmann <adrian@cadifra.com>
parents:
16807
diff
changeset
|
380 def samefile(path1, path2): |
6fc7fd72ba3e
win32.py: let samefile and samedevice work on directories too
Adrian Buehlmann <adrian@cadifra.com>
parents:
16807
diff
changeset
|
381 '''Returns whether path1 and path2 refer to the same file or directory.''' |
6fc7fd72ba3e
win32.py: let samefile and samedevice work on directories too
Adrian Buehlmann <adrian@cadifra.com>
parents:
16807
diff
changeset
|
382 res1 = _getfileinfo(path1) |
6fc7fd72ba3e
win32.py: let samefile and samedevice work on directories too
Adrian Buehlmann <adrian@cadifra.com>
parents:
16807
diff
changeset
|
383 res2 = _getfileinfo(path2) |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
384 return (res1.dwVolumeSerialNumber == res2.dwVolumeSerialNumber |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
385 and res1.nFileIndexHigh == res2.nFileIndexHigh |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
386 and res1.nFileIndexLow == res2.nFileIndexLow) |
10218
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9198
diff
changeset
|
387 |
17006
6fc7fd72ba3e
win32.py: let samefile and samedevice work on directories too
Adrian Buehlmann <adrian@cadifra.com>
parents:
16807
diff
changeset
|
388 def samedevice(path1, path2): |
6fc7fd72ba3e
win32.py: let samefile and samedevice work on directories too
Adrian Buehlmann <adrian@cadifra.com>
parents:
16807
diff
changeset
|
389 '''Returns whether path1 and path2 are on the same device.''' |
6fc7fd72ba3e
win32.py: let samefile and samedevice work on directories too
Adrian Buehlmann <adrian@cadifra.com>
parents:
16807
diff
changeset
|
390 res1 = _getfileinfo(path1) |
6fc7fd72ba3e
win32.py: let samefile and samedevice work on directories too
Adrian Buehlmann <adrian@cadifra.com>
parents:
16807
diff
changeset
|
391 res2 = _getfileinfo(path2) |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
392 return res1.dwVolumeSerialNumber == res2.dwVolumeSerialNumber |
10218
750b7a4f01f6
Add support for relinking on Windows.
Siddharth Agarwal <sid.bugzilla@gmail.com>
parents:
9198
diff
changeset
|
393 |
24652
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
394 def peekpipe(pipe): |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
395 handle = msvcrt.get_osfhandle(pipe.fileno()) |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
396 avail = _DWORD() |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
397 |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
398 if not _kernel32.PeekNamedPipe(handle, None, 0, None, ctypes.byref(avail), |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
399 None): |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
400 err = _kernel32.GetLastError() |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
401 if err == _ERROR_BROKEN_PIPE: |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
402 return 0 |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
403 raise ctypes.WinError(err) |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
404 |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
405 return avail.value |
232bf0028596
win32: add a method to fetch the available pipe data size
Matt Harbison <matt_harbison@yahoo.com>
parents:
24494
diff
changeset
|
406 |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
407 def testpid(pid): |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
408 '''return True if pid is still running or unable to |
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
409 determine, False otherwise''' |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
410 h = _kernel32.OpenProcess(_PROCESS_QUERY_INFORMATION, False, pid) |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
411 if h: |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
412 try: |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
413 status = _DWORD() |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
414 if _kernel32.GetExitCodeProcess(h, ctypes.byref(status)): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
415 return status.value == _STILL_ACTIVE |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
416 finally: |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
417 _kernel32.CloseHandle(h) |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
418 return _kernel32.GetLastError() != _ERROR_INVALID_PARAMETER |
2054
e18beba54a7e
fix exception handling on windows.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
419 |
14236
e949a008999d
rename util.executable_path to executablepath
Adrian Buehlmann <adrian@cadifra.com>
parents:
14235
diff
changeset
|
420 def executablepath(): |
13376
60b5c6c3fd12
win32: new function executable_path
Adrian Buehlmann <adrian@cadifra.com>
parents:
13375
diff
changeset
|
421 '''return full path of hg.exe''' |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
422 size = 600 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
423 buf = ctypes.create_string_buffer(size + 1) |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
424 len = _kernel32.GetModuleFileNameA(None, ctypes.byref(buf), size) |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
425 if len == 0: |
24494
f2b87f4856bf
win32: add comment about WinError
Adrian Buehlmann <adrian@cadifra.com>
parents:
24418
diff
changeset
|
426 raise ctypes.WinError() # Note: WinError is a function |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
427 elif len == size: |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
428 raise ctypes.WinError(_ERROR_INSUFFICIENT_BUFFER) |
13376
60b5c6c3fd12
win32: new function executable_path
Adrian Buehlmann <adrian@cadifra.com>
parents:
13375
diff
changeset
|
429 return buf.value |
60b5c6c3fd12
win32: new function executable_path
Adrian Buehlmann <adrian@cadifra.com>
parents:
13375
diff
changeset
|
430 |
35514
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
431 def getfstype(path): |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
432 """Get the filesystem type name from a directory or file (best-effort) |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
433 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
434 Returns None if we are unsure. Raises OSError on ENOENT, EPERM, etc. |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
435 """ |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
436 # realpath() calls GetFullPathName() |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
437 realpath = os.path.realpath(path) |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
438 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
439 size = len(realpath) + 1 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
440 buf = ctypes.create_string_buffer(size) |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
441 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
442 if not _kernel32.GetVolumePathNameA(realpath, ctypes.byref(buf), size): |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
443 raise ctypes.WinError() # Note: WinError is a function |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
444 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
445 t = _kernel32.GetDriveTypeA(buf.value) |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
446 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
447 if t == _DRIVE_REMOTE: |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
448 return 'cifs' |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
449 elif t not in (_DRIVE_REMOVABLE, _DRIVE_FIXED, _DRIVE_CDROM, |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
450 _DRIVE_RAMDISK): |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
451 return None |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
452 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
453 size = 256 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
454 name = ctypes.create_string_buffer(size) |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
455 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
456 if not _kernel32.GetVolumeInformationA(buf.value, None, 0, None, None, None, |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
457 ctypes.byref(name), size): |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
458 raise ctypes.WinError() # Note: WinError is a function |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
459 |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
460 return name.value |
2062f7c2ac83
win32: implement util.getfstype()
Matt Harbison <matt_harbison@yahoo.com>
parents:
34040
diff
changeset
|
461 |
7890
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
462 def getuser(): |
e710f0f592b2
util: split out posix, windows, and win32 modules
Matt Mackall <mpm@selenic.com>
parents:
7778
diff
changeset
|
463 '''return name of current user''' |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
464 size = _DWORD(300) |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
465 buf = ctypes.create_string_buffer(size.value + 1) |
14345
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
466 if not _advapi32.GetUserNameA(ctypes.byref(buf), ctypes.byref(size)): |
24418
a2285e2fc949
win32: 'raise ctypes.WinError' -> 'raise ctypes.WinError()'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21226
diff
changeset
|
467 raise ctypes.WinError() |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
468 return buf.value |
4672
272c0a09b203
Handle CTRL+C in serve under Windows.
Marcos Chaves <marcos.nospam@gmail.com>
parents:
4407
diff
changeset
|
469 |
14237
4d684d8210a1
rename util.set_signal_handler to setsignalhandler
Adrian Buehlmann <adrian@cadifra.com>
parents:
14236
diff
changeset
|
470 _signalhandler = [] |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
471 |
14237
4d684d8210a1
rename util.set_signal_handler to setsignalhandler
Adrian Buehlmann <adrian@cadifra.com>
parents:
14236
diff
changeset
|
472 def setsignalhandler(): |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
473 '''Register a termination handler for console events including |
4672
272c0a09b203
Handle CTRL+C in serve under Windows.
Marcos Chaves <marcos.nospam@gmail.com>
parents:
4407
diff
changeset
|
474 CTRL+C. python signal handlers do not work well with socket |
272c0a09b203
Handle CTRL+C in serve under Windows.
Marcos Chaves <marcos.nospam@gmail.com>
parents:
4407
diff
changeset
|
475 operations. |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
476 ''' |
4672
272c0a09b203
Handle CTRL+C in serve under Windows.
Marcos Chaves <marcos.nospam@gmail.com>
parents:
4407
diff
changeset
|
477 def handler(event): |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
478 _kernel32.ExitProcess(1) |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
479 |
14237
4d684d8210a1
rename util.set_signal_handler to setsignalhandler
Adrian Buehlmann <adrian@cadifra.com>
parents:
14236
diff
changeset
|
480 if _signalhandler: |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
481 return # already registered |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
482 h = _SIGNAL_HANDLER(handler) |
14237
4d684d8210a1
rename util.set_signal_handler to setsignalhandler
Adrian Buehlmann <adrian@cadifra.com>
parents:
14236
diff
changeset
|
483 _signalhandler.append(h) # needed to prevent garbage collection |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
484 if not _kernel32.SetConsoleCtrlHandler(h, True): |
24418
a2285e2fc949
win32: 'raise ctypes.WinError' -> 'raise ctypes.WinError()'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21226
diff
changeset
|
485 raise ctypes.WinError() |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
486 |
10240
3af4b39afe2a
cmdutil: hide child window created by win32 spawndetached()
Patrick Mezard <pmezard@gmail.com>
parents:
10219
diff
changeset
|
487 def hidewindow(): |
3af4b39afe2a
cmdutil: hide child window created by win32 spawndetached()
Patrick Mezard <pmezard@gmail.com>
parents:
10219
diff
changeset
|
488 |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
489 def callback(hwnd, pid): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
490 wpid = _DWORD() |
14345
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
491 _user32.GetWindowThreadProcessId(hwnd, ctypes.byref(wpid)) |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
492 if pid == wpid.value: |
14345
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
493 _user32.ShowWindow(hwnd, _SW_HIDE) |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
494 return False # stop enumerating windows |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
495 return True |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
496 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
497 pid = _kernel32.GetCurrentProcessId() |
14345
bf9a105aed0a
win32.py: add argtypes and restype
Adrian Buehlmann <adrian@cadifra.com>
parents:
14344
diff
changeset
|
498 _user32.EnumWindows(_WNDENUMPROC(callback), pid) |
11012
81631f0cf13b
win32: detect console width on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
10388
diff
changeset
|
499 |
30327
365812902904
scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents:
30326
diff
changeset
|
500 def termsize(): |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
501 # cmd.exe does not handle CR like a unix console, the CR is |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
502 # counted in the line length. On 80 columns consoles, if 80 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
503 # characters are written, the following CR won't apply on the |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
504 # current line but on the new one. Keep room for it. |
30326
392633d7860e
scmutil: clarify that we explicitly do termwidth - 1 on Windows
Yuya Nishihara <yuya@tcha.org>
parents:
25994
diff
changeset
|
505 width = 80 - 1 |
30327
365812902904
scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents:
30326
diff
changeset
|
506 height = 25 |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
507 # Query stderr to avoid problems with redirections |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
508 screenbuf = _kernel32.GetStdHandle( |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
509 _STD_ERROR_HANDLE) # don't close the handle returned |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
510 if screenbuf is None or screenbuf == _INVALID_HANDLE_VALUE: |
30327
365812902904
scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents:
30326
diff
changeset
|
511 return width, height |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
512 csbi = _CONSOLE_SCREEN_BUFFER_INFO() |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
513 if not _kernel32.GetConsoleScreenBufferInfo( |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
514 screenbuf, ctypes.byref(csbi)): |
30327
365812902904
scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents:
30326
diff
changeset
|
515 return width, height |
30326
392633d7860e
scmutil: clarify that we explicitly do termwidth - 1 on Windows
Yuya Nishihara <yuya@tcha.org>
parents:
25994
diff
changeset
|
516 width = csbi.srWindow.Right - csbi.srWindow.Left # don't '+ 1' |
30327
365812902904
scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents:
30326
diff
changeset
|
517 height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1 |
365812902904
scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents:
30326
diff
changeset
|
518 return width, height |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
519 |
32684
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
520 def enablevtmode(): |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
521 '''Enable virtual terminal mode for the associated console. Return True if |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
522 enabled, else False.''' |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
523 |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
524 ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4 |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
525 |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
526 handle = _kernel32.GetStdHandle(_STD_OUTPUT_HANDLE) # don't close the handle |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
527 if handle == _INVALID_HANDLE_VALUE: |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
528 return False |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
529 |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
530 mode = _DWORD(0) |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
531 |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
532 if not _kernel32.GetConsoleMode(handle, ctypes.byref(mode)): |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
533 return False |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
534 |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
535 if (mode.value & ENABLE_VIRTUAL_TERMINAL_PROCESSING) == 0: |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
536 mode.value |= ENABLE_VIRTUAL_TERMINAL_PROCESSING |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
537 |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
538 if not _kernel32.SetConsoleMode(handle, mode): |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
539 return False |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
540 |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
541 return True |
2d56e6d23be7
win32: add a method to enable ANSI color code processing on Windows 10
Matt Harbison <matt_harbison@yahoo.com>
parents:
30670
diff
changeset
|
542 |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
543 def spawndetached(args): |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
544 # No standard library function really spawns a fully detached |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
545 # process under win32 because they allocate pipes or other objects |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
546 # to handle standard streams communications. Passing these objects |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
547 # to the child process requires handle inheritance to be enabled |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
548 # which makes really detached processes impossible. |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
549 si = _STARTUPINFO() |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
550 si.cb = ctypes.sizeof(_STARTUPINFO) |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
551 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
552 pi = _PROCESS_INFORMATION() |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
553 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
554 env = '' |
30642
344e68882cd3
py3: replace os.environ with encoding.environ (part 4 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30327
diff
changeset
|
555 for k in encoding.environ: |
344e68882cd3
py3: replace os.environ with encoding.environ (part 4 of 5)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30327
diff
changeset
|
556 env += "%s=%s\0" % (k, encoding.environ[k]) |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
557 if not env: |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
558 env = '\0' |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
559 env += '\0' |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
560 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
561 args = subprocess.list2cmdline(args) |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
562 |
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
563 res = _kernel32.CreateProcessA( |
17050
e780fb37168b
win32: specify _CREATE_NO_WINDOW on spawndetached()
Adrian Buehlmann <adrian@cadifra.com>
parents:
17006
diff
changeset
|
564 None, args, None, None, False, _CREATE_NO_WINDOW, |
30670
5861bdbeb9a3
py3: use pycompat.getcwd instead of os.getcwd
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30642
diff
changeset
|
565 env, pycompat.getcwd(), ctypes.byref(si), ctypes.byref(pi)) |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
566 if not res: |
24418
a2285e2fc949
win32: 'raise ctypes.WinError' -> 'raise ctypes.WinError()'
Matt Harbison <matt_harbison@yahoo.com>
parents:
21226
diff
changeset
|
567 raise ctypes.WinError() |
13375
f1fa8f481c7c
port win32.py to using the Python ctypes library
Adrian Buehlmann <adrian@cadifra.com>
parents:
13374
diff
changeset
|
568 |
32696
4c3d9ee87382
win32: drop a py26 daemonizing hack
Matt Harbison <matt_harbison@yahoo.com>
parents:
32684
diff
changeset
|
569 return pi.dwProcessId |
13775
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
570 |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
571 def unlink(f): |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
572 '''try to implement POSIX' unlink semantics on Windows''' |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
573 |
21226
4898c37e03c0
win32: backout 1a9ebc83a74c
Steve Borho <steve@borho.org>
parents:
21193
diff
changeset
|
574 if os.path.isdir(f): |
4898c37e03c0
win32: backout 1a9ebc83a74c
Steve Borho <steve@borho.org>
parents:
21193
diff
changeset
|
575 # use EPERM because it is POSIX prescribed value, even though |
4898c37e03c0
win32: backout 1a9ebc83a74c
Steve Borho <steve@borho.org>
parents:
21193
diff
changeset
|
576 # unlink(2) on directories returns EISDIR on Linux |
4898c37e03c0
win32: backout 1a9ebc83a74c
Steve Borho <steve@borho.org>
parents:
21193
diff
changeset
|
577 raise IOError(errno.EPERM, |
4898c37e03c0
win32: backout 1a9ebc83a74c
Steve Borho <steve@borho.org>
parents:
21193
diff
changeset
|
578 "Unlinking directory not permitted: '%s'" % f) |
19159
1b329f8c7b24
windows: check target type before actual unlinking to follow POSIX semantics
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
18959
diff
changeset
|
579 |
13775
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
580 # POSIX allows to unlink and rename open files. Windows has serious |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
581 # problems with doing that: |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
582 # - Calling os.unlink (or os.rename) on a file f fails if f or any |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
583 # hardlinked copy of f has been opened with Python's open(). There is no |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
584 # way such a file can be deleted or renamed on Windows (other than |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
585 # scheduling the delete or rename for the next reboot). |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
586 # - Calling os.unlink on a file that has been opened with Mercurial's |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
587 # posixfile (or comparable methods) will delay the actual deletion of |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
588 # the file for as long as the file is held open. The filename is blocked |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
589 # during that time and cannot be used for recreating a new file under |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
590 # that same name ("zombie file"). Directories containing such zombie files |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
591 # cannot be removed or moved. |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
592 # A file that has been opened with posixfile can be renamed, so we rename |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
593 # f to a random temporary name before calling os.unlink on it. This allows |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
594 # callers to recreate f immediately while having other readers do their |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
595 # implicit zombie filename blocking on a temporary name. |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
596 |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
597 for tries in xrange(10): |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
598 temp = '%s-%08x' % (f, random.randint(0, 0xffffffff)) |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
599 try: |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
600 os.rename(f, temp) # raises OSError EEXIST if temp exists |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
601 break |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24652
diff
changeset
|
602 except OSError as e: |
13775
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
603 if e.errno != errno.EEXIST: |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
604 raise |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
605 else: |
18175
fd3f8b87b682
win32: clean up use of two-argument raise
Augie Fackler <raf@durin42.com>
parents:
17428
diff
changeset
|
606 raise IOError(errno.EEXIST, "No usable temporary filename found") |
13775
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
607 |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
608 try: |
930efdc6bfa4
windows: move unlink to win32.py
Adrian Buehlmann <adrian@cadifra.com>
parents:
13379
diff
changeset
|
609 os.unlink(temp) |
13776
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
610 except OSError: |
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
611 # The unlink might have failed because the READONLY attribute may heave |
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
612 # been set on the original file. Rename works fine with READONLY set, |
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
613 # but not os.unlink. Reset all attributes and try again. |
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
614 _kernel32.SetFileAttributesA(temp, _FILE_ATTRIBUTE_NORMAL) |
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
615 try: |
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
616 os.unlink(temp) |
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
617 except OSError: |
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
618 # The unlink might have failed due to some very rude AV-Scanners. |
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
619 # Leaking a tempfile is the lesser evil than aborting here and |
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
620 # leaving some potentially serious inconsistencies. |
a2f0fdb1e488
win32: remove READONLY attribute on unlink
Adrian Buehlmann <adrian@cadifra.com>
parents:
13775
diff
changeset
|
621 pass |
13795
43b5fe18ea6c
set NOT_CONTENT_INDEXED on .hg dir (issue2694)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13776
diff
changeset
|
622 |
43b5fe18ea6c
set NOT_CONTENT_INDEXED on .hg dir (issue2694)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13776
diff
changeset
|
623 def makedir(path, notindexed): |
43b5fe18ea6c
set NOT_CONTENT_INDEXED on .hg dir (issue2694)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13776
diff
changeset
|
624 os.mkdir(path) |
43b5fe18ea6c
set NOT_CONTENT_INDEXED on .hg dir (issue2694)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13776
diff
changeset
|
625 if notindexed: |
43b5fe18ea6c
set NOT_CONTENT_INDEXED on .hg dir (issue2694)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13776
diff
changeset
|
626 _kernel32.SetFileAttributesA(path, _FILE_ATTRIBUTE_NOT_CONTENT_INDEXED) |