Example #1
0
    def check_for_truncated_files(self, runner):
        """Returns the number of files that have been detected to be truncated.
        This function expects that all files to check for truncation live in the public dir"""
        ret = 0

        if "check_trunc_files" not in runner.enabled or not self._check_truncation:
            return ret

        for dump_fname in self.list_outfiles_to_check_for_truncation(
                runner.dump_dir):
            dfile = DumpFile(runner.wiki, runner.dump_dir.filename_public_path(
                dump_fname), dump_fname)

            file_truncated = True
            if exists(dfile.filename):
                if dfile.check_if_empty():
                    # file exists and is empty, move it out of the way
                    dfile.rename(dfile.filename + ".empty")
                elif dfile.check_if_truncated():
                    # The file exists and is truncated, we move it out of the way
                    dfile.rename(dfile.filename + ".truncated")

                    # We detected a failure and could abort right now. However,
                    # there might still be some further file parts, that are good.
                    # Hence, we go on treating the remaining files and in the end
                    # /all/ truncated files have been moved out of the way. So we
                    # see, which parts (instead of the whole job) need a rerun.
                else:
                    # The file exists and is not truncated. Heck, it's a good file!
                    file_truncated = False

            else:
                # file doesn't exist, move on
                file_truncated = False
            if file_truncated:
                ret += 1

        return ret