Esempio n. 1
0
    def _hardlinkDup(self, path, chksum, cursor):
        if not os.path.islink(path):
            pathInode = os.stat(path).st_ino
            links = []
            cursor.execute(
                "select path from files where chksum = ? and path != ? and symlink = 0;",
                (chksum, path))

            # i.e. find all different files with the same checksum
            for row in cursor:
                (link, ) = row
                if os.stat(link).st_ino != pathInode:
                    links.append(
                        link
                    )  # only hardlink files that don't point at the same inode

            if len(links) > 0:
                # let's assume that an existing entry is newer than this one.  Otherwise, we are constantly
                # relinking files
                canonicalLink = links[0]
                del links[0]
                links.append(path)

                # clean up any links with different inodes
                for link in links:
                    cursor.execute(LINK_UPDATE, (1, link))
                    linkFile(canonicalLink, link)
Esempio n. 2
0
	def testLinkSymlink(self):
		link = "sha1link.txt"
		fsu.symlinkFile(self._sha1file, link)
		
		self.assertSymlink(link)
		
		# try to hard link link; this should be a no-op
		fsu.linkFile(self._sha1file, link)
		
		self.assertSymlink(link)
		self.assertUnlinked(link)
Esempio n. 3
0
	def testLinkFile(self):
		link = "sha1hardlink.txt"
		fsu.linkFile(self._sha1file, link)
		
		self.assertLink(link)
		
		# link again, just to make sure it won't fail
		fsu.linkFile(self._sha1file, link)
		
		self.assertLink(link)
		self.assertUnlinked(link)
Esempio n. 4
0
	def testLinkFileBad(self):
		self.assertRaises(OSError, lambda: fsu.linkFile(None, None))
		self.assertRaises(OSError, lambda: fsu.linkFile("", ""))
		self.assertRaises(OSError, lambda: fsu.linkFile(None, ""))
		self.assertRaises(OSError, lambda: fsu.linkFile("", None))
		self.assertRaises(OSError, lambda: fsu.linkFile(self._sha1file, ""))
		self.assertRaises(OSError, lambda: fsu.linkFile(self._sha1file, None))
Esempio n. 5
0
  def _hardlinkDup(self, path, chksum, cursor):
    if not os.path.islink(path):
      pathInode = os.stat(path).st_ino
      links = []
      cursor.execute("select path from files where chksum = ? and path != ? and symlink = 0;", 
            (chksum, path))
          
      # i.e. find all different files with the same checksum
      for row in cursor:
        (link, ) = row
        if os.stat(link).st_ino != pathInode:
          links.append(link) # only hardlink files that don't point at the same inode
      
      if len(links) > 0:
        # let's assume that an existing entry is newer than this one.  Otherwise, we are constantly
        # relinking files
        canonicalLink = links[0]
        del links[0]
        links.append(path)

        # clean up any links with different inodes
        for link in links:
          cursor.execute(LINK_UPDATE, (1, link))
          linkFile(canonicalLink, link)