Exemple #1
0
    def _storeArtifact(cls, content: IO[bytes], path: FilePath) -> None:
        """Verify and store an artifact from a temporary file.
        If the file is valid, store it at the given path.
        If the file is not valid, raise ValueError.
        """

        cls.verify(content)

        # Copy content.
        content.seek(0, 0)
        uploadPath = path.siblingExtension('.part')
        path.parent().makedirs(ignoreExistingDirectory=True)
        with uploadPath.open('wb') as out:
            while True:
                data = content.read(cls.putBlockSize)
                if not data:
                    break
                out.write(data)
            out.flush()
            fsync(out.fileno())
        replace(uploadPath.path, path.path)
        path.changed()