Show More
@@ -716,6 +716,29 b' def checklink(path):' | |||
|
716 | 716 | except (OSError, AttributeError): |
|
717 | 717 | return False |
|
718 | 718 | |
|
719 | def checknlink(testfile): | |
|
720 | '''check whether hardlink count reporting works properly''' | |
|
721 | f = testfile + ".hgtmp" | |
|
722 | ||
|
723 | try: | |
|
724 | os_link(testfile, f) | |
|
725 | except OSError, inst: | |
|
726 | if inst.errno == errno.EINVAL: | |
|
727 | # FS doesn't support creating hardlinks | |
|
728 | return True | |
|
729 | return False | |
|
730 | ||
|
731 | try: | |
|
732 | # nlinks() may behave differently for files on Windows shares if | |
|
733 | # the file is open. | |
|
734 | fd = open(f) | |
|
735 | return nlinks(f) > 1 | |
|
736 | finally: | |
|
737 | fd.close() | |
|
738 | os.unlink(f) | |
|
739 | ||
|
740 | return False | |
|
741 | ||
|
719 | 742 | def endswithsep(path): |
|
720 | 743 | '''Check path ends with os.sep or os.altsep.''' |
|
721 | 744 | return path.endswith(os.sep) or os.altsep and path.endswith(os.altsep) |
@@ -840,6 +863,7 b' class opener(object):' | |||
|
840 | 863 | else: |
|
841 | 864 | self.auditor = always |
|
842 | 865 | self.createmode = None |
|
866 | self._trustnlink = None | |
|
843 | 867 | |
|
844 | 868 | @propertycache |
|
845 | 869 | def _can_symlink(self): |
@@ -873,13 +897,20 b' class opener(object):' | |||
|
873 | 897 | os.unlink(f) |
|
874 | 898 | nlink = 0 |
|
875 | 899 | else: |
|
900 | # nlinks() may behave differently for files on Windows | |
|
901 | # shares if the file is open. | |
|
902 | fd = open(f) | |
|
876 | 903 | nlink = nlinks(f) |
|
877 | except OSError: | |
|
904 | fd.close() | |
|
905 | except (OSError, IOError): | |
|
878 | 906 | nlink = 0 |
|
879 | 907 | if not os.path.isdir(dirname): |
|
880 | 908 | makedirs(dirname, self.createmode) |
|
881 |
if nlink > |
|
|
882 | rename(mktempcopy(f), f) | |
|
909 | if nlink > 0: | |
|
910 | if self._trustnlink is None: | |
|
911 | self._trustnlink = nlink > 1 or checknlink(f) | |
|
912 | if nlink > 1 or not self._trustnlink: | |
|
913 | rename(mktempcopy(f), f) | |
|
883 | 914 | fp = posixfile(f, mode) |
|
884 | 915 | if nlink == 0: |
|
885 | 916 | if st_mode is None: |
@@ -43,17 +43,7 b' def _getfileinfo(pathname):' | |||
|
43 | 43 | |
|
44 | 44 | def nlinks(pathname): |
|
45 | 45 | """Return number of hardlinks for the given file.""" |
|
46 |
|
|
|
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 | |
|
46 | return _getfileinfo(pathname)[7] | |
|
57 | 47 | |
|
58 | 48 | def samefile(fpath1, fpath2): |
|
59 | 49 | """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