def dump(self, hash_value): hash_value = hash_value.lower() reldirname = shard(hash_value, 2, 2) metaabsdirname = os.path.join(self.ROOT_PATH, *reldirname) # TODO: detect rights issue in directory structure if os.path.isfile(metaabsdirname): lines = self._read_meta(metaabsdirname) for line in lines: print(line) else: print("File not in Metadata DB")
def verify_files(self, force): # randomize the order of processing so that for lengthy # operations all files have a change to be checked if process has # to be aborted and is restarted later parentdirs = list(range(0x0000, 0xffff)) shuffle(parentdirs) index = 0 for start_hash in parentdirs: sys.stdout.write("%d%% (%d) \r" % (index*100>>16, index)) sys.stdout.flush() index = index + 1 hash_value = '{:04x}'.format(start_hash) reldirname = shard(hash_value, 2, 2) mediaabsdirname = os.path.join(self.ROOT_PATH, *reldirname) if os.path.isdir(mediaabsdirname): LOGGER.debug('Verifying files in %s', mediaabsdirname) self._verify_files_in_dir(reldirname, mediaabsdirname, force)
def verify_files(self, force): # randomize the order of processing so that for lengthy # operations all files have a change to be checked if process has # to be aborted and is restarted later parentdirs = list(range(0x0000, 0xffff)) shuffle(parentdirs) index = 0 for start_hash in parentdirs: sys.stdout.write("%d%% (%d) \r" % (index * 100 >> 16, index)) sys.stdout.flush() index = index + 1 hash_value = '{:04x}'.format(start_hash) reldirname = shard(hash_value, 2, 2) mediaabsdirname = os.path.join(self.ROOT_PATH, *reldirname) if os.path.isdir(mediaabsdirname): LOGGER.debug('Verifying files in %s', mediaabsdirname) self._verify_files_in_dir(reldirname, mediaabsdirname, force)
def import_file(self, src, reflink): """Import a single media file. Args: src (str): The path to the file to import reflink (bool): Use a reflink if the backend FS supports it Returns: Nothing. """ srcfullpath = os.path.abspath(src) srcfullpath = os.path.realpath(srcfullpath) # compute the hash and relative path to the file hash_value = hash_file(srcfullpath) reldirname = shard(hash_value, 2, 2) (dstfullpath, is_duplicate) = self.media_db.import_file(srcfullpath, reldirname, reflink) self.metadata_db.import_file(srcfullpath, dstfullpath, reldirname)