diff --git a/.changes/next-release/bugfix-S3-3229.json b/.changes/next-release/bugfix-S3-3229.json new file mode 100644 index 000000000000..dd87b30c380e --- /dev/null +++ b/.changes/next-release/bugfix-S3-3229.json @@ -0,0 +1,5 @@ +{ + "type": "bugfix", + "category": "S3", + "description": "S3 commands that encountered both an error and warning will now return the RC for error instead of warning." +} diff --git a/awscli/customizations/s3/subcommands.py b/awscli/customizations/s3/subcommands.py index da30d6692e6d..2ce9ead2b75a 100644 --- a/awscli/customizations/s3/subcommands.py +++ b/awscli/customizations/s3/subcommands.py @@ -1082,7 +1082,7 @@ def run(self): rc = 0 if files[0].num_tasks_failed > 0: rc = 1 - if files[0].num_tasks_warned > 0: + elif files[0].num_tasks_warned > 0: rc = 2 return rc diff --git a/tests/functional/s3/test_cp_command.py b/tests/functional/s3/test_cp_command.py index b51a39dd1593..5e3c5a3b5aa4 100644 --- a/tests/functional/s3/test_cp_command.py +++ b/tests/functional/s3/test_cp_command.py @@ -14,7 +14,7 @@ import mock from awscli.testutils import BaseAWSCommandParamsTest, FileCreator -from awscli.testutils import capture_input +from awscli.testutils import capture_input, set_invalid_utime from awscli.compat import six @@ -459,6 +459,23 @@ def test_upload_unicode_path(self): progress_message = 'Completed 10 Bytes' self.assertIn(progress_message, stdout) + def test_cp_with_error_and_warning(self): + command = "s3 cp %s s3://bucket/foo.txt" + self.parsed_responses = [{ + 'Error': { + 'Code': 'NoSuchBucket', + 'Message': 'The specified bucket does not exist', + 'BucketName': 'bucket' + } + }] + self.http_response.status_code = 404 + + full_path = self.files.create_file('foo.txt', 'bar') + set_invalid_utime(full_path) + _, stderr, rc = self.run_cmd(command % full_path, expected_rc=1) + self.assertIn('upload failed', stderr) + self.assertIn('warning: File has an invalid timestamp.', stderr) + class TestStreamingCPCommand(BaseAWSCommandParamsTest): def test_streaming_upload(self):