def FileFinderOSFromClient(args): """This function expands paths from the args and returns related stat entries. Args: args: An `rdf_file_finder.FileFinderArgs` object. Yields: `rdf_paths.PathSpec` instances. """ stat_cache = utils.StatCache() opts = args.action.stat for path in GetExpandedPaths(args): try: for content_condition in _ParseContentConditions(args): result = list(content_condition.Search(path)) if not result: raise _SkipFileException() stat = stat_cache.Get(path, follow_symlink=opts.resolve_links) stat_entry = client_utils.StatEntryFromStatPathSpec( stat, ext_attrs=opts.collect_ext_attrs) yield stat_entry except _SkipFileException: pass
def FileFinderOSFromClient( args: rdf_file_finder.FileFinderArgs ) -> Iterator[rdf_client_fs.StatEntry]: """This function expands paths from the args and returns related stat entries. Args: args: A proto message with arguments for the file finder action. Yields: Stat entries corresponding to the found files. """ stat_cache = filesystem.StatCache() opts = args.action.stat for path in GetExpandedPaths(args): try: content_conditions = conditions.ContentCondition.Parse( args.conditions) for content_condition in content_conditions: with io.open(path, "rb") as fd: result = list(content_condition.Search(fd)) if not result: raise _SkipFileException() stat = stat_cache.Get(path, follow_symlink=opts.resolve_links) stat_entry = client_utils.StatEntryFromStatPathSpec( stat, ext_attrs=opts.collect_ext_attrs) yield stat_entry except _SkipFileException: pass
def FileFinderOSFromClient(args): """This function expands paths from the args and returns related stat entries. Args: args: An `rdf_file_finder.FileFinderArgs` object. Yields: `rdf_paths.PathSpec` instances. """ stat_cache = filesystem.StatCache() opts = args.action.stat for path in GetExpandedPaths(args): try: content_conditions = conditions.ContentCondition.Parse( args.conditions) for content_condition in content_conditions: with io.open(path, "rb") as fd: result = list(content_condition.Search(fd)) if not result: raise _SkipFileException() # TODO: `opts.resolve_links` has type `RDFBool`, not `bool`. stat = stat_cache.Get(path, follow_symlink=bool(opts.resolve_links)) stat_entry = client_utils.StatEntryFromStatPathSpec( stat, ext_attrs=opts.collect_ext_attrs) yield stat_entry except _SkipFileException: pass
def Execute(self, filepath, result): stat_cache = self.flow.stat_cache # TODO: `self.opts.resolve_links` is `RDFBool`, not `bool`. stat = stat_cache.Get(filepath, follow_symlink=bool(self.opts.resolve_links)) result.stat_entry = client_utils.StatEntryFromStatPathSpec( stat, ext_attrs=self.opts.collect_ext_attrs)
def Start(cls, args): stat_cache = utils.StatCache() opts = args.action.stat for path in _GetExpandedPaths(args): try: stat = stat_cache.Get(path, follow_symlink=opts.resolve_links) stat_entry = client_utils.StatEntryFromStatPathSpec( stat, ext_attrs=opts.collect_ext_attrs) yield stat_entry except _SkipFileException: pass
def Execute(self, filepath, result): stat = self.flow.stat_cache.Get(filepath, follow_symlink=True) result.stat_entry = client_utils.StatEntryFromStatPathSpec( stat, ext_attrs=self.opts.collect_ext_attrs) if stat.IsDirectory(): return policy = self.opts.oversized_file_policy max_size = self.opts.max_size if stat.GetSize() <= self.opts.max_size: result.hash_entry = _HashEntry(stat, self.flow) elif policy == self.opts.OversizedFilePolicy.HASH_TRUNCATED: result.hash_entry = _HashEntry(stat, self.flow, max_size=max_size) elif policy == self.opts.OversizedFilePolicy.SKIP: return else: raise ValueError("Unknown oversized file policy: %s" % policy)
def Execute(self, filepath, result): stat_cache = self.flow.stat_cache stat = stat_cache.Get(filepath, follow_symlink=self.opts.resolve_links) result.stat_entry = client_utils.StatEntryFromStatPathSpec( stat, ext_attrs=self.opts.collect_ext_attrs)