##// END OF EJS Templates
Don't link file again if it's already a correct hard link...
Thomas Kluyver -
Show More
@@ -554,6 +554,12 b' def link_or_copy(src, dst):'
554 554
555 555 link_errno = link(src, dst)
556 556 if link_errno == errno.EEXIST:
557 if os.stat(src).st_ino == os.stat(dst).st_ino:
558 # dst is already a hard link to the correct file, so we don't need
559 # to do anything else. If we try to link and rename the file
560 # anyway, we get duplicate files - see http://bugs.python.org/issue21876
561 return
562
557 563 new_dst = dst + "-temp-%04X" %(random.randint(1, 16**4), )
558 564 try:
559 565 link_or_copy(src, new_dst)
@@ -676,3 +676,12 b' class TestLinkOrCopy(object):'
676 676 dst = self.dst("target")
677 677 path.link_or_copy(self.src, dst)
678 678 self.assert_content_equal(self.src, dst)
679
680 def test_link_twice(self):
681 # Linking the same file twice shouldn't leave duplicates around.
682 # See https://github.com/ipython/ipython/issues/6450
683 dst = self.dst('target')
684 path.link_or_copy(self.src, dst)
685 path.link_or_copy(self.src, dst)
686 self.assert_inode_equal(self.src, dst)
687 nt.assert_equal(sorted(os.listdir(self.tempdir.name)), ['src', 'target'])
General Comments 0
You need to be logged in to leave comments. Login now