@flow.StateHandler(next_state="IterateFind")
  def IterateFind(self, responses):
    """Iterate in this state until no more results are available."""
    if not responses.success:
      raise IOError(responses.status)

    for response in responses:
      # Create the file in the VFS
      vfs_urn = aff4.AFF4Object.VFSGRRClient.PathspecToURN(
          response.hit.pathspec, self.client_id)

      response.hit.aff4path = vfs_urn

      # TODO(user): This ends up being fairly expensive.
      if stat.S_ISDIR(response.hit.st_mode):
        fd = aff4.FACTORY.Create(vfs_urn, "VFSDirectory", token=self.token)
      else:
        fd = aff4.FACTORY.Create(vfs_urn, "VFSFile", token=self.token)

      stat_response = fd.Schema.STAT(response.hit)
      fd.Set(stat_response)

      fd.Set(fd.Schema.PATHSPEC(response.hit.pathspec))
      fd.Close(sync=False)

      # Send the stat to the parent flow.
      self.SendReply(stat_response)

    self.state.received_count += len(responses)

    # Exit if we hit the max result count we wanted or we're finished. Note that
    # we may exceed the max_results if the iteration yielded too many results,
    # we simply will not return to the client for another iteration.
    if (self.state.received_count < self.state.args.max_results and
        responses.iterator.state != responses.iterator.State.FINISHED):

      self.state.args.findspec.iterator = responses.iterator

      # If we are close to max_results reduce the iterator.
      self.state.args.findspec.iterator.number = min(
          self.state.args.findspec.iterator.number,
          self.state.args.max_results - self.state.received_count)

      self.CallClient("Find", self.state.args.findspec,
                      next_state="IterateFind")
      self.Log("%d files processed.", self.state.received_count)
dataset/ETHPy150Open google/grr/grr/lib/flows/general/find.py/FindFiles.IterateFind/original