##// END OF EJS Templates
win32: remove useless lstat() fallback in nlinks()...
Patrick Mezard -
r11992:ccd8e592 stable
parent child Browse files
Show More
@@ -34,20 +34,16 b' def _getfileinfo(pathname):'
34 34 fh = win32file.CreateFile(pathname,
35 35 win32file.GENERIC_READ, win32file.FILE_SHARE_READ,
36 36 None, win32file.OPEN_EXISTING, 0, None)
37 try:
38 return win32file.GetFileInformationByHandle(fh)
39 finally:
40 fh.Close()
41 37 except pywintypes.error:
42 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()
43 43
44 44 def nlinks(pathname):
45 45 """Return number of hardlinks for the given file."""
46 res = _getfileinfo(pathname)
47 if res is not None:
48 links = res[7]
49 else:
50 links = os.lstat(pathname).st_nlink
46 links = _getfileinfo(pathname)[7]
51 47 if links < 2:
52 48 # Known to be wrong for most network drives
53 49 dirname = os.path.dirname(pathname)
@@ -64,21 +60,15 b' def samefile(fpath1, fpath2):'
64 60 guaranteed to work for files, not directories."""
65 61 res1 = _getfileinfo(fpath1)
66 62 res2 = _getfileinfo(fpath2)
67 if res1 is not None and res2 is not None:
68 # Index 4 is the volume serial number, and 8 and 9 contain the file ID
69 return res1[4] == res2[4] and res1[8] == res2[8] and res1[9] == res2[9]
70 else:
71 return False
63 # 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]
72 65
73 66 def samedevice(fpath1, fpath2):
74 67 """Returns whether fpath1 and fpath2 are on the same device. This is only
75 68 guaranteed to work for files, not directories."""
76 69 res1 = _getfileinfo(fpath1)
77 70 res2 = _getfileinfo(fpath2)
78 if res1 is not None and res2 is not None:
79 return res1[4] == res2[4]
80 else:
81 return False
71 return res1[4] == res2[4]
82 72
83 73 def testpid(pid):
84 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