Show More
@@ -23,15 +23,6 b' from win32com.shell import shell, shellc' | |||
|
23 | 23 | def os_link(src, dst): |
|
24 | 24 | try: |
|
25 | 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 | 26 | except pywintypes.error: |
|
36 | 27 | raise OSError(errno.EINVAL, 'target implements hardlinks improperly') |
|
37 | 28 | except NotImplementedError: # Another fake error win Win98 |
@@ -43,41 +34,41 b' def _getfileinfo(pathname):' | |||
|
43 | 34 | fh = win32file.CreateFile(pathname, |
|
44 | 35 | win32file.GENERIC_READ, win32file.FILE_SHARE_READ, |
|
45 | 36 | None, win32file.OPEN_EXISTING, 0, None) |
|
46 | try: | |
|
47 | return win32file.GetFileInformationByHandle(fh) | |
|
48 | finally: | |
|
49 | fh.Close() | |
|
50 | 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 | 44 | def nlinks(pathname): |
|
54 | 45 | """Return number of hardlinks for the given file.""" |
|
55 |
|
|
|
56 | if res is not None: | |
|
57 | return res[7] | |
|
58 | else: | |
|
59 | return os.lstat(pathname).st_nlink | |
|
46 | links = _getfileinfo(pathname)[7] | |
|
47 | if links < 2: | |
|
48 | # Known to be wrong for most network drives | |
|
49 | dirname = os.path.dirname(pathname) | |
|
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 | 58 | def samefile(fpath1, fpath2): |
|
62 | 59 | """Returns whether fpath1 and fpath2 refer to the same file. This is only |
|
63 | 60 | guaranteed to work for files, not directories.""" |
|
64 | 61 | res1 = _getfileinfo(fpath1) |
|
65 | 62 | res2 = _getfileinfo(fpath2) |
|
66 | if res1 is not None and res2 is not None: | |
|
67 | # Index 4 is the volume serial number, and 8 and 9 contain the file ID | |
|
68 | return res1[4] == res2[4] and res1[8] == res2[8] and res1[9] == res2[9] | |
|
69 | else: | |
|
70 | 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] | |
|
71 | 65 | |
|
72 | 66 | def samedevice(fpath1, fpath2): |
|
73 | 67 | """Returns whether fpath1 and fpath2 are on the same device. This is only |
|
74 | 68 | guaranteed to work for files, not directories.""" |
|
75 | 69 | res1 = _getfileinfo(fpath1) |
|
76 | 70 | res2 = _getfileinfo(fpath2) |
|
77 | if res1 is not None and res2 is not None: | |
|
78 | return res1[4] == res2[4] | |
|
79 | else: | |
|
80 | return False | |
|
71 | return res1[4] == res2[4] | |
|
81 | 72 | |
|
82 | 73 | def testpid(pid): |
|
83 | 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