def fake_hash_suffix(suffix_dir, policy): # check that the suffix dir is empty and remove it just like the # real _hash_suffix self.assertEqual([self._hash], os.listdir(suffix_dir)) hash_dir = os.path.join(suffix_dir, self._hash) self.assertEqual([], os.listdir(hash_dir)) os.rmdir(hash_dir) os.rmdir(suffix_dir) raise PathNotDir()
def hash_suffix(path, reclaim_age): """ Performs reclamation and returns an md5 of all (remaining) files. :param reclaim_age: age in seconds at which to remove tombstones :raises PathNotDir: if given path is not a valid directory :raises OSError: for non-ENOTDIR errors """ md5 = hashlib.md5() try: path_contents = sorted(os.listdir(path)) except OSError, err: if err.errno in (errno.ENOTDIR, errno.ENOENT): raise PathNotDir() raise
def hash_suffix(path, reclaim_age): """ Performs reclamation and returns an md5 of all (remaining) files. :param reclaim_age: age in seconds at which to remove tombstones :raises PathNotDir: if given path is not a valid directory :raises OSError: for non-ENOTDIR errors """ md5 = hashlib.md5() try: path_contents = sorted(os.listdir(path)) except OSError as err: if err.errno in (errno.ENOTDIR, errno.ENOENT): raise PathNotDir() raise for hsh in path_contents: hsh_path = join(path, hsh) try: files = hash_cleanup_listdir(hsh_path, reclaim_age) except OSError as err: if err.errno == errno.ENOTDIR: partition_path = dirname(path) objects_path = dirname(partition_path) device_path = dirname(objects_path) quar_path = quarantine_renamer(device_path, hsh_path) logging.exception( _('Quarantined %s to %s because it is not a directory') % (hsh_path, quar_path)) continue raise if not files: os.rmdir(hsh_path) for filename in files: md5.update(filename) try: os.rmdir(path) except OSError: pass return md5.hexdigest()