##// END OF EJS Templates
opener: check hardlink count reporting (issue1866)...
Adrian Buehlmann -
r12938:bf826c0b stable
parent child Browse files
Show More
@@ -716,6 +716,29 b' def checklink(path):'
716 except (OSError, AttributeError):
716 except (OSError, AttributeError):
717 return False
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 def endswithsep(path):
742 def endswithsep(path):
720 '''Check path ends with os.sep or os.altsep.'''
743 '''Check path ends with os.sep or os.altsep.'''
721 return path.endswith(os.sep) or os.altsep and path.endswith(os.altsep)
744 return path.endswith(os.sep) or os.altsep and path.endswith(os.altsep)
@@ -840,6 +863,7 b' class opener(object):'
840 else:
863 else:
841 self.auditor = always
864 self.auditor = always
842 self.createmode = None
865 self.createmode = None
866 self._trustnlink = None
843
867
844 @propertycache
868 @propertycache
845 def _can_symlink(self):
869 def _can_symlink(self):
@@ -873,13 +897,20 b' class opener(object):'
873 os.unlink(f)
897 os.unlink(f)
874 nlink = 0
898 nlink = 0
875 else:
899 else:
900 # nlinks() may behave differently for files on Windows
901 # shares if the file is open.
902 fd = open(f)
876 nlink = nlinks(f)
903 nlink = nlinks(f)
877 except OSError:
904 fd.close()
905 except (OSError, IOError):
878 nlink = 0
906 nlink = 0
879 if not os.path.isdir(dirname):
907 if not os.path.isdir(dirname):
880 makedirs(dirname, self.createmode)
908 makedirs(dirname, self.createmode)
881 if nlink > 1:
909 if nlink > 0:
882 rename(mktempcopy(f), f)
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 fp = posixfile(f, mode)
914 fp = posixfile(f, mode)
884 if nlink == 0:
915 if nlink == 0:
885 if st_mode is None:
916 if st_mode is None:
@@ -43,17 +43,7 b' def _getfileinfo(pathname):'
43
43
44 def nlinks(pathname):
44 def nlinks(pathname):
45 """Return number of hardlinks for the given file."""
45 """Return number of hardlinks for the given file."""
46 links = _getfileinfo(pathname)[7]
46 return _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
57
47
58 def samefile(fpath1, fpath2):
48 def samefile(fpath1, fpath2):
59 """Returns whether fpath1 and fpath2 refer to the same file. This is only
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