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 | |
@@ -54,9 +45,19 b' 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 | res = _getfileinfo(pathname) | |
56 | if res is not None: |
|
47 | if res is not None: | |
57 |
|
|
48 | links = res[7] | |
58 | else: |
|
49 | else: | |
59 |
|
|
50 | links = os.lstat(pathname).st_nlink | |
|
51 | if links < 2: | |||
|
52 | # Known to be wrong for most network drives | |||
|
53 | dirname = os.path.dirname(pathname) | |||
|
54 | if not dirname: | |||
|
55 | dirname = '.' | |||
|
56 | dt = win32file.GetDriveType(dirname + '\\') | |||
|
57 | if dt == 4 or dt == 1: | |||
|
58 | # Fake hardlink to force COW for network drives | |||
|
59 | links = 2 | |||
|
60 | return links | |||
60 |
|
61 | |||
61 | def samefile(fpath1, fpath2): |
|
62 | def samefile(fpath1, fpath2): | |
62 | """Returns whether fpath1 and fpath2 refer to the same file. This is only |
|
63 | """Returns whether fpath1 and fpath2 refer to the same file. This is only |
General Comments 0
You need to be logged in to leave comments.
Login now