From: Eric Ball Date: Fri, 13 Aug 2021 01:40:17 +0000 (-0700) Subject: Fix: Move text/html mimetype check to after None X-Git-Tag: v0.35.7^0 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=b2835f462d9c072a10afa2c1edc3436855f1231a;p=releng%2Flftools.git Fix: Move text/html mimetype check to after None When checking mimetype during _upload_to_s3, the newly-added text/html type was checking before it is checked for None, which is a potential TypeError. By moving it after the variable is checked for None, the feature is safe without requiring any further modifications. Change-Id: Ia945893adb8973608cb9527b4ea811a5610d6aba Signed-off-by: Eric Ball --- diff --git a/lftools/deploy.py b/lftools/deploy.py index fbf8ea6b..183ccddb 100755 --- a/lftools/deploy.py +++ b/lftools/deploy.py @@ -447,16 +447,16 @@ def deploy_s3(s3_bucket, s3_path, build_url, workspace, pattern=None): log.error(e) return False return True - elif mimetypes.guess_type(file)[0] in "text/html": - extra_args = text_html_extra_args + elif mimetypes.guess_type(file)[0] is None or mimetypes.guess_type(file)[0] in "text/plain": + extra_args = text_plain_extra_args try: s3.Bucket(s3_bucket).upload_file(file, "{}{}".format(s3_path, file), ExtraArgs=extra_args) except ClientError as e: log.error(e) return False return True - elif mimetypes.guess_type(file)[0] is None or mimetypes.guess_type(file)[0] in "text/plain": - extra_args = text_plain_extra_args + elif mimetypes.guess_type(file)[0] in "text/html": + extra_args = text_html_extra_args try: s3.Bucket(s3_bucket).upload_file(file, "{}{}".format(s3_path, file), ExtraArgs=extra_args) except ClientError as e: diff --git a/releasenotes/notes/fix-deploy-mimetype-889dd0182fea051b.yaml b/releasenotes/notes/fix-deploy-mimetype-889dd0182fea051b.yaml new file mode 100644 index 00000000..6c015af3 --- /dev/null +++ b/releasenotes/notes/fix-deploy-mimetype-889dd0182fea051b.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + When checking mimetype during _upload_to_s3, the newly-added text/html type + was checking before it is checked for None, which is a potential TypeError. + By moving it after the variable is checked for None, the feature is safe + without requiring any further modifications.