Mercurial > public > mercurial-scm > hg
comparison mercurial/win32.py @ 10218:750b7a4f01f6 stable
Add support for relinking on Windows.
Test and minor code change by Patrick M?zard <pmezard@gmail.com>
author | Siddharth Agarwal <sid.bugzilla@gmail.com> |
---|---|
date | Fri, 08 Jan 2010 18:48:39 +0530 |
parents | 061eeb602354 |
children | 3b94120864fc |
comparison
equal
deleted
inserted
replaced
10217:2bbb4c8eb27e | 10218:750b7a4f01f6 |
---|---|
35 except pywintypes.error, details: | 35 except pywintypes.error, details: |
36 raise OSError(errno.EINVAL, 'target implements hardlinks improperly') | 36 raise OSError(errno.EINVAL, 'target implements hardlinks improperly') |
37 except NotImplementedError: # Another fake error win Win98 | 37 except NotImplementedError: # Another fake error win Win98 |
38 raise OSError(errno.EINVAL, 'Hardlinking not supported') | 38 raise OSError(errno.EINVAL, 'Hardlinking not supported') |
39 | 39 |
40 def nlinks(pathname): | 40 def _getfileinfo(pathname): |
41 """Return number of hardlinks for the given file.""" | 41 """Return number of hardlinks for the given file.""" |
42 try: | 42 try: |
43 fh = win32file.CreateFile(pathname, | 43 fh = win32file.CreateFile(pathname, |
44 win32file.GENERIC_READ, win32file.FILE_SHARE_READ, | 44 win32file.GENERIC_READ, win32file.FILE_SHARE_READ, |
45 None, win32file.OPEN_EXISTING, 0, None) | 45 None, win32file.OPEN_EXISTING, 0, None) |
46 res = win32file.GetFileInformationByHandle(fh) | 46 res = win32file.GetFileInformationByHandle(fh) |
47 fh.Close() | 47 fh.Close() |
48 return res | |
49 except pywintypes.error: | |
50 return None | |
51 | |
52 def nlinks(pathname): | |
53 """Return number of hardlinks for the given file.""" | |
54 res = _getfileinfo(pathname) | |
55 if res is not None: | |
48 return res[7] | 56 return res[7] |
49 except pywintypes.error: | 57 else: |
50 return os.lstat(pathname).st_nlink | 58 return os.lstat(pathname).st_nlink |
59 | |
60 def samefile(fpath1, fpath2): | |
61 """Returns whether fpath1 and fpath2 refer to the same file. This is only | |
62 guaranteed to work for files, not directories.""" | |
63 res1 = _getfileinfo(fpath1) | |
64 res2 = _getfileinfo(fpath2) | |
65 if res1 is not None and res2 is not None: | |
66 # Index 4 is the volume serial number, and 8 and 9 contain the file ID | |
67 return res1[4] == res2[4] and res1[8] == res2[8] and res1[9] == res2[9] | |
68 else: | |
69 return False | |
70 | |
71 def samedevice(fpath1, fpath2): | |
72 """Returns whether fpath1 and fpath2 are on the same device. This is only | |
73 guaranteed to work for files, not directories.""" | |
74 res1 = _getfileinfo(fpath1) | |
75 res2 = _getfileinfo(fpath2) | |
76 if res1 is not None and res2 is not None: | |
77 return res1[4] == res2[4] | |
78 else: | |
79 return False | |
51 | 80 |
52 def testpid(pid): | 81 def testpid(pid): |
53 '''return True if pid is still running or unable to | 82 '''return True if pid is still running or unable to |
54 determine, False otherwise''' | 83 determine, False otherwise''' |
55 try: | 84 try: |