##// END OF EJS Templates
Merge with stable
Patrick Mezard -
r11993:9bce7ed5 merge default
parent child Browse files
Show More
@@ -23,15 +23,6 b' from win32com.shell import shell, shellc'
23 def os_link(src, dst):
23 def os_link(src, dst):
24 try:
24 try:
25 win32file.CreateHardLink(dst, src)
25 win32file.CreateHardLink(dst, src)
26 # CreateHardLink sometimes succeeds on mapped drives but
27 # following nlinks() returns 1. Check it now and bail out.
28 if nlinks(src) < 2:
29 try:
30 win32file.DeleteFile(dst)
31 except:
32 pass
33 # Fake hardlinking error
34 raise OSError(errno.EINVAL, 'Hardlinking not supported')
35 except pywintypes.error:
26 except pywintypes.error:
36 raise OSError(errno.EINVAL, 'target implements hardlinks improperly')
27 raise OSError(errno.EINVAL, 'target implements hardlinks improperly')
37 except NotImplementedError: # Another fake error win Win98
28 except NotImplementedError: # Another fake error win Win98
@@ -43,41 +34,41 b' def _getfileinfo(pathname):'
43 fh = win32file.CreateFile(pathname,
34 fh = win32file.CreateFile(pathname,
44 win32file.GENERIC_READ, win32file.FILE_SHARE_READ,
35 win32file.GENERIC_READ, win32file.FILE_SHARE_READ,
45 None, win32file.OPEN_EXISTING, 0, None)
36 None, win32file.OPEN_EXISTING, 0, None)
46 try:
47 return win32file.GetFileInformationByHandle(fh)
48 finally:
49 fh.Close()
50 except pywintypes.error:
37 except pywintypes.error:
51 return None
38 raise OSError(errno.ENOENT, 'The system cannot find the file specified')
39 try:
40 return win32file.GetFileInformationByHandle(fh)
41 finally:
42 fh.Close()
52
43
53 def nlinks(pathname):
44 def nlinks(pathname):
54 """Return number of hardlinks for the given file."""
45 """Return number of hardlinks for the given file."""
55 res = _getfileinfo(pathname)
46 links = _getfileinfo(pathname)[7]
56 if res is not None:
47 if links < 2:
57 return res[7]
48 # Known to be wrong for most network drives
58 else:
49 dirname = os.path.dirname(pathname)
59 return os.lstat(pathname).st_nlink
50 if not dirname:
51 dirname = '.'
52 dt = win32file.GetDriveType(dirname + '\\')
53 if dt == 4 or dt == 1:
54 # Fake hardlink to force COW for network drives
55 links = 2
56 return links
60
57
61 def samefile(fpath1, fpath2):
58 def samefile(fpath1, fpath2):
62 """Returns whether fpath1 and fpath2 refer to the same file. This is only
59 """Returns whether fpath1 and fpath2 refer to the same file. This is only
63 guaranteed to work for files, not directories."""
60 guaranteed to work for files, not directories."""
64 res1 = _getfileinfo(fpath1)
61 res1 = _getfileinfo(fpath1)
65 res2 = _getfileinfo(fpath2)
62 res2 = _getfileinfo(fpath2)
66 if res1 is not None and res2 is not None:
63 # Index 4 is the volume serial number, and 8 and 9 contain the file ID
67 # Index 4 is the volume serial number, and 8 and 9 contain the file ID
64 return res1[4] == res2[4] and res1[8] == res2[8] and res1[9] == res2[9]
68 return res1[4] == res2[4] and res1[8] == res2[8] and res1[9] == res2[9]
69 else:
70 return False
71
65
72 def samedevice(fpath1, fpath2):
66 def samedevice(fpath1, fpath2):
73 """Returns whether fpath1 and fpath2 are on the same device. This is only
67 """Returns whether fpath1 and fpath2 are on the same device. This is only
74 guaranteed to work for files, not directories."""
68 guaranteed to work for files, not directories."""
75 res1 = _getfileinfo(fpath1)
69 res1 = _getfileinfo(fpath1)
76 res2 = _getfileinfo(fpath2)
70 res2 = _getfileinfo(fpath2)
77 if res1 is not None and res2 is not None:
71 return res1[4] == res2[4]
78 return res1[4] == res2[4]
79 else:
80 return False
81
72
82 def testpid(pid):
73 def testpid(pid):
83 '''return True if pid is still running or unable to
74 '''return True if pid is still running or unable to
General Comments 0
You need to be logged in to leave comments. Login now