예제 #1
0
    def _copy_input_files(self, writer):
        for file in self._input_files:
            dest_file = "/tmp/submission-src"
            put_file(container=writer, src=file, dest=dest_file)

            with file.open("rb") as f:
                mimetype = get_file_mimetype(f)

            if mimetype.lower() == "application/zip":
                # Unzip the file in the container rather than in the python
                # process. With resource limits this should provide some
                # protection against zip bombs etc.
                writer.exec_run(
                    f"unzip {dest_file} -d /input/ -x '__MACOSX/*'")

                # Remove a duplicated directory
                input_files = (writer.exec_run(
                    f"ls -1 /input/").output.decode().splitlines())

                if (len(input_files) == 1 and not writer.exec_run(
                        f"ls -d /input/{input_files[0]}/").exit_code):
                    writer.exec_run(
                        f'/bin/sh -c "mv /input/{input_files[0]}/* /input/ '
                        f'&& rm -r /input/{input_files[0]}/"')

            else:
                # Not a zip file, so must be a csv
                writer.exec_run(f"mv {dest_file} /input/submission.csv")
예제 #2
0
    def _copy_input_files(self, writer):
        for file in self._input_files:
            dest_file = '/tmp/submission-src'
            put_file(container=writer, src=file, dest=dest_file)

            with file.open('rb') as f:
                mimetype = get_file_mimetype(f)

            if mimetype.lower() == 'application/zip':
                # Unzip the file in the container rather than in the python
                # process. With resource limits this should provide some
                # protection against zip bombs etc.
                writer.exec_run(f'unzip {dest_file} -d /input/')
            else:
                # Not a zip file, so must be a csv
                writer.exec_run(f'mv {dest_file} /input/submission.csv')
예제 #3
0
    def _copy_input_files(self, writer):
        for file in self._input_files:
            dest_file = "/tmp/submission-src"
            put_file(container=writer, src=file, dest=dest_file)

            with file.open("rb") as f:
                mimetype = get_file_mimetype(f)

            if mimetype.lower() == "application/zip":
                # Unzip the file in the container rather than in the python
                # process. With resource limits this should provide some
                # protection against zip bombs etc.
                writer.exec_run(
                    f"unzip {dest_file} -d /input/ -x '__MACOSX/*'")
                self.__was_unzipped = True
            else:
                # Not a zip file, so must be a csv
                writer.exec_run(f"mv {dest_file} /input/submission.csv")
예제 #4
0
    def _copy_input_files(self, writer):
        for file in self._input_files:
            dest_file = "/tmp/submission-src"
            put_file(container=writer, src=file, dest=dest_file)

            with file.open("rb") as f:
                mimetype = get_file_mimetype(f)

            if mimetype.lower() == "application/zip":
                # Unzip the file in the container rather than in the python
                # process. With resource limits this should provide some
                # protection against zip bombs etc.
                writer.exec_run(
                    f"unzip {dest_file} -d /input/ -x '__MACOSX/*'"
                )
                self.__was_unzipped = True
            else:
                # Not a zip file, so must be a csv
                writer.exec_run(f"mv {dest_file} /input/submission.csv")
예제 #5
0
    def _copy_input_files(self, writer):
        for file in self._input_files:
            dest_file = "/tmp/submission-src"
            put_file(container=writer, src=file, dest=dest_file)

            with file.open("rb") as f:
                mimetype = get_file_mimetype(f)

            if mimetype.lower() == "application/zip":
                # Unzip the file in the container rather than in the python
                # process. With resource limits this should provide some
                # protection against zip bombs etc.
                writer.exec_run(
                    f"unzip {dest_file} -d /input/ -x '__MACOSX/*'"
                )

                # Remove a duplicated directory
                input_files = (
                    writer.exec_run(f"ls -1 /input/")
                    .output.decode()
                    .splitlines()
                )

                if (
                    len(input_files) == 1
                    and not writer.exec_run(
                        f"ls -d /input/{input_files[0]}/"
                    ).exit_code
                ):
                    writer.exec_run(
                        f'/bin/sh -c "mv /input/{input_files[0]}/* /input/ '
                        f'&& rm -r /input/{input_files[0]}/"'
                    )

            else:
                # Not a zip file, so must be a csv
                writer.exec_run(f"mv {dest_file} /input/submission.csv")