Пример #1
0
    def NewAFF4Directory(cls, resolver, version, root_urn):
        result = AFF4Directory(resolver)
        result.version = version
        result.root_path = root_urn.ToFilename()

        mode = resolver.GetUnique(lexicon.transient_graph, root_urn,
                                  lexicon.AFF4_STREAM_WRITE_MODE)
        if mode == "truncate":
            aff4_utils.RemoveDirectory(result.root_path)

        if not (os.path.isdir(result.root_path)
                or os.path.isfile(result.root_path)):
            if mode == "truncate" or mode == "append":
                aff4_utils.MkDir(result.root_path)
            else:
                raise RuntimeError("Unknown mode")

        resolver.Set(lexicon.transient_graph, result.urn, lexicon.AFF4_TYPE,
                     rdfvalue.URN(lexicon.AFF4_DIRECTORY_TYPE))

        resolver.Set(lexicon.transient_graph, result.urn, lexicon.AFF4_STORED,
                     rdfvalue.URN(root_urn))

        result.LoadFromURN()

        return resolver.CachePut(result)
Пример #2
0
    def _CreateIntermediateDirectories(components):
        """Recursively create intermediate directories."""
        path = os.sep

        if aff4.WIN32:
            # On windows we do not want a leading \ (e.g. C:\windows not
            # \C:\Windows)
            path = ""

        for component in components:
            path = path + component + os.sep
            LOGGER.info("Creating intermediate directories %s", path)

            if os.isdir(path):
                continue

            # Directory does not exist - Try to make it.
            try:
                aff4_utils.MkDir(path)
                continue
            except IOError as e:
                LOGGER.error("Unable to create intermediate directory: %s", e)
                raise