<s> """<STR_LIT>""" <EOL> import stat <EOL> from grr . lib import aff4 <EOL> from grr . lib import flow <EOL> from grr . lib . rdfvalues import structs as rdf_structs <EOL> from grr . proto import flows_pb2 <EOL> class FindFilesArgs ( rdf_structs . RDFProtoStruct ) : <EOL> protobuf = flows_pb2 . FindFilesArgs <EOL> def Validate ( self ) : <EOL> """<STR_LIT>""" <EOL> self . findspec . Validate ( ) <EOL> class FindFiles ( flow . GRRFlow ) : <EOL> r"""<STR_LIT>""" <EOL> category = "<STR_LIT>" <EOL> args_type = FindFilesArgs <EOL> friendly_name = "<STR_LIT>" <EOL> @ flow . StateHandler ( next_state = "<STR_LIT>" ) <EOL> def Start ( self , unused_response ) : <EOL> """<STR_LIT>""" <EOL> self . state . Register ( "<STR_LIT>" , <NUM_LIT:0> ) <EOL> self . state . Register ( "<STR_LIT>" , None ) <EOL> self . args . findspec . iterator . number = self . args . iteration_count <EOL> if self . args . findspec . path_glob : <EOL> self . args . findspec . path_regex = self . args . findspec . path_glob . AsRegEx ( ) <EOL> self . CallClient ( "<STR_LIT>" , self . state . args . findspec , next_state = "<STR_LIT>" ) <EOL> @ flow . StateHandler ( next_state = "<STR_LIT>" ) <EOL> def IterateFind ( self , responses ) : <EOL> """<STR_LIT>""" <EOL> if not responses . success : <EOL> raise IOError ( responses . status ) <EOL> for response in responses : <EOL> vfs_urn = aff4 . AFF4Object . VFSGRRClient . PathspecToURN ( <EOL> response . hit . pathspec , self . client_id ) <EOL> response . hit . aff4path = vfs_urn <EOL> if stat . S_ISDIR ( response . hit . st_mode ) : <EOL> fd = aff4 . FACTORY . Create ( vfs_urn , "<STR_LIT>" , token = self . token ) <EOL> else : <EOL> fd = aff4 . FACTORY . Create ( vfs_urn , "<STR_LIT>" , token = self . token ) <EOL> stat_response = fd . Schema . STAT ( response . hit ) <EOL> fd . Set ( stat_response ) <EOL> fd . Set ( fd . Schema . PATHSPEC ( response . hit . pathspec ) ) <EOL> fd . Close ( sync = False ) <EOL> self . SendReply ( stat_response ) <EOL> self . state . received_count += len ( responses ) <EOL> if ( self . state . received_count < self . state . args . max_results and <EOL> responses . iterator . state != responses . iterator . State . FINISHED ) : <EOL> self . state . args . findspec . iterator = responses . iterator <EOL> self . state . args . findspec . iterator . number = min ( <EOL> self . state . args . findspec . iterator . number , <EOL> self . state . args . max_results - self . state . received_count ) <EOL> self . CallClient ( "<STR_LIT>" , self . state . args . findspec , <EOL> next_state = "<STR_LIT>" ) <EOL> self . Log ( "<STR_LIT>" , self . state . received_count ) </s>
