def __init__(self, args):
     self.args = args
     self.cert_dir = self.log_dir = os.path.abspath(
         os.path.join(args.workdir, "certs"))
     if not os.path.isdir(self.cert_dir):
         os.makedirs(self.cert_dir)
     self.hash_fs = hashfs.HashFS(self.cert_dir,
                                  depth=4,
                                  width=1,
                                  algorithm='sha256')
Example #2
0
def test_hashfs_repair(fs, stringio):
    original_address = fs.put(stringio)
    newfs = hashfs.HashFS(fs.root, depth=1)

    repaired = newfs.repair()

    assert len(repaired) == 1
    original_path, address = repaired[0]

    assert original_path == original_address.abspath
    assert not os.path.isfile(original_path)
    assert_file_put(newfs, address)
Example #3
0
    def __init__(self, args, files=None, metadata=None):
        self.args = args
        self.meta = metadata
        self.file_db = files

        if self.file_db is None:
            db_dir = os.path.join(self.args.workdir, "webext_data")
            if not os.path.isdir(db_dir):
                os.makedirs(db_dir)
            self.file_db = hashfs.HashFS(db_dir, depth=4, width=1, algorithm='sha256')

        if self.meta is None:
            self.meta = md.Metadata(filename=md.get_metadata_file(self.args))
Example #4
0
 def __enter__(self):
     if not self.path.exists():
         self.path.mkdir(parents=True)
         log.debug('Created directory {} for store'.format(self.path))
     elif not self.path.is_dir():
         raise FileExistsError('{} exists but is not a directory'.format(
             self.path))
     self._cas = hashfs.HashFS(str(self.path / 'content'),
                               depth=4,
                               width=1,
                               algorithm='sha1')
     self._init_db()
     return self
Example #5
0
    def setup(self):
        """
        Performs all the setup shared among multiple runs of the mode.
        Put everything here that takes too long for __init__().
        :return: None
        """
        if self.files is None:
            db_dir = os.path.join(self.workdir, "webext_data")
            if not os.path.isdir(db_dir):
                os.makedirs(db_dir)
            self.files = hashfs.HashFS(db_dir,
                                       depth=4,
                                       width=1,
                                       algorithm='sha256')

        if self.meta is None:
            self.meta = md.Metadata(filename=md.get_metadata_file(self.args))

        if self.db is None:
            self.db = db.Database(self.args,
                                  files=self.files,
                                  metadata=self.meta)

        return True
Example #6
0
def fs(testpath):
    return hashfs.HashFS(str(testpath))
Example #7
0
def ext_db(raw_meta, hfs_tmp):
    edb = hashfs.HashFS(hfs_tmp, depth=4, width=1, algorithm='sha256')
    amo.update_files(raw_meta, edb)
    return edb