def __init__(self, session=None, **kwargs):
        cache_dir = session.GetParameter("cache_dir")

        if not cache_dir:
            raise io_manager.IOManagerError(
                "Local profile cache is not configured - "
                "add a cache_dir parameter to ~/.rekallrc.")

        # Cache dir may be specified relative to the home directory.
        if config.GetHomeDir():
            cache_dir = os.path.join(config.GetHomeDir(), cache_dir)

        if not os.access(cache_dir, os.F_OK | os.R_OK | os.W_OK | os.X_OK):
            try:
                os.makedirs(cache_dir)
            except (IOError, OSError):
                raise io_manager.IOManagerError(
                    "Unable to create or access cache directory %s" %
                    cache_dir)

        # We use an IO manager to manage the cache directory directly.
        self.cache_io_manager = io_manager.DirectoryIOManager(urn=cache_dir,
                                                              session=session)
        self.url_manager = self.DELEGATE(session=session, **kwargs)

        self.CheckUpstreamRepository()

        super(CachingManager, self).__init__(session=session, **kwargs)
Beispiel #2
0
def GetCacheDir(session):
    """Returns the path of a usable cache directory."""
    cache_dir = os.path.expandvars(session.GetParameter("cache_dir"))

    if not cache_dir:
        raise io_manager.IOManagerError(
            "Local profile cache is not configured - "
            "add a cache_dir parameter to ~/.rekallrc.")

    # Cache dir may be specified relative to the home directory.
    cache_dir = os.path.join(config.GetHomeDir(session), cache_dir)

    if not os.access(cache_dir, os.F_OK | os.R_OK | os.W_OK | os.X_OK):
        try:
            os.makedirs(cache_dir)
        except (IOError, OSError):
            raise io_manager.IOManagerError(
                "Unable to create or access cache directory %s" % cache_dir)

    return cache_dir