Пример #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 tearDown(self):
     aff4_utils.RemoveDirectory(self.root_path)