예제 #1
0
    def testCorrectlyReportProgressForSuccessfullyCollectedFiles(self):
        path = os.path.join(self.fixture_path, "b*")

        flow_id = flow_test_lib.TestFlowHelper(
            file.CollectMultipleFiles.__name__,
            self.client_mock,
            client_id=self.client_id,
            path_expressions=[path],
            creator=self.test_username)

        progress = flow_test_lib.GetFlowProgress(self.client_id, flow_id)
        self.assertEqual(
            rdf_file_finder.CollectMultipleFilesProgress(
                num_collected=2,
                num_failed=0,
                num_found=2,
                num_in_progress=0,
                num_raw_fs_access_retries=0,
            ), progress)
예제 #2
0
파일: file.py 프로젝트: khanhgithead/grr
    def Start(self):
        """See base class."""
        super().Start(file_size=self.MAX_FILE_SIZE)

        self.state.progress = rdf_file_finder.CollectMultipleFilesProgress(
            num_found=0,
            num_in_progress=0,
            num_raw_fs_access_retries=0,
            num_collected=0,
            num_failed=0,
        )

        conditions = []

        if self.args.HasField("modification_time"):
            conditions.append(
                rdf_file_finder.FileFinderCondition(
                    condition_type=rdf_file_finder.FileFinderCondition.Type.
                    MODIFICATION_TIME,
                    modification_time=self.args.modification_time,
                ))

        if self.args.HasField("access_time"):
            conditions.append(
                rdf_file_finder.FileFinderCondition(
                    condition_type=rdf_file_finder.FileFinderCondition.Type.
                    ACCESS_TIME,
                    access_time=self.args.access_time,
                ))

        if self.args.HasField("inode_change_time"):
            conditions.append(
                rdf_file_finder.FileFinderCondition(
                    condition_type=rdf_file_finder.FileFinderCondition.Type.
                    INODE_CHANGE_TIME,
                    inode_change_time=self.args.inode_change_time,
                ))

        if self.args.HasField("size"):
            conditions.append(
                rdf_file_finder.FileFinderCondition(
                    condition_type=rdf_file_finder.FileFinderCondition.Type.
                    SIZE,
                    size=self.args.size,
                ))

        if self.args.HasField("ext_flags"):
            conditions.append(
                rdf_file_finder.FileFinderCondition(
                    condition_type=rdf_file_finder.FileFinderCondition.Type.
                    EXT_FLAGS,
                    ext_flags=self.args.ext_flags,
                ))

        if self.args.HasField("contents_regex_match"):
            conditions.append(
                rdf_file_finder.FileFinderCondition(
                    condition_type=rdf_file_finder.FileFinderCondition.Type.
                    CONTENTS_REGEX_MATCH,
                    contents_regex_match=self.args.contents_regex_match,
                ))

        if self.args.HasField("contents_literal_match"):
            conditions.append(
                rdf_file_finder.FileFinderCondition(
                    condition_type=rdf_file_finder.FileFinderCondition.Type.
                    CONTENTS_LITERAL_MATCH,
                    contents_literal_match=self.args.contents_literal_match,
                ))

        file_finder_args = rdf_file_finder.FileFinderArgs(
            paths=self.args.path_expressions,
            pathtype=rdf_paths.PathSpec.PathType.OS,
            conditions=conditions,
            action=rdf_file_finder.FileFinderAction.Stat())

        self.CallFlow(file_finder.ClientFileFinder.__name__,
                      flow_args=file_finder_args,
                      next_state=self.ProcessFiles.__name__)