예제 #1
0
    def Run(self, args: rdf_file_finder.FileFinderArgs):
        action = self._ParseAction(args)
        content_conditions = list(
            conditions.ContentCondition.Parse(args.conditions))
        metadata_conditions = list(
            conditions.MetadataCondition.Parse(args.conditions))

        for path in _GetExpandedPaths(args, heartbeat_cb=self.Progress):
            self.Progress()
            pathspec = rdf_paths.PathSpec(path=path, pathtype=args.pathtype)

            with vfs.VFSOpen(pathspec) as vfs_file:
                stat_entry = vfs_file.Stat()

                # Conversion from StatEntry to os.stat_result is lossy. Some checks do
                # not work (e.g. extended attributes).
                stat_obj = client_utils.StatResultFromStatEntry(stat_entry)
                fs_stat = filesystem.Stat(path=path, stat_obj=stat_obj)
                if not all(
                        cond.Check(fs_stat) for cond in metadata_conditions):
                    continue

                matches = _CheckConditionsShortCircuit(content_conditions,
                                                       pathspec)
                if content_conditions and not matches:
                    continue  # Skip if any condition yielded no matches.

                result = action(stat_entry=stat_entry, fd=vfs_file)
                result.matches = matches
                self.SendReply(result)
예제 #2
0
 def testStatResultFromStatEntry(self):
   stat_obj = os.stat_result([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
   fs_stat = filesystem.Stat("/foo", stat_obj)
   pathspec = rdf_paths.PathSpec(path="/foo", pathtype="OS")
   stat_entry = client_utils.StatEntryFromStat(
       fs_stat, pathspec, ext_attrs=False)
   self.assertEqual(stat_obj, client_utils.StatResultFromStatEntry(stat_entry))