@@ -247,6 +247,27 @@ def test_mv_to_nonexistent_bucket(self):
247247 p = aws ('s3 mv %s s3://bad-noexist-13143242/foo.txt' % (full_path ,))
248248 self .assertEqual (p .rc , 1 )
249249
250+ def test_cant_move_file_onto_itself_small_file (self ):
251+ # We don't even need a remote file in this case. We can
252+ # immediately validate that we can't move a file onto itself.
253+ bucket_name = self .create_bucket ()
254+ self .put_object (bucket_name , key_name = 'key.txt' , contents = 'foo' )
255+ p = aws ('s3 mv s3://%s/key.txt s3://%s/key.txt' % (bucket_name , bucket_name ))
256+ self .assertEqual (p .rc , 255 )
257+ self .assertIn ('Cannot mv a file onto itself' , p .stderr )
258+
259+ def test_cant_move_large_file_onto_itself (self ):
260+ # At the API level, you can multipart copy an object onto itself,
261+ # but a mv command doesn't make sense because a mv is just a
262+ # cp + an rm of the src file. We should be consistent and
263+ # not allow large files to be mv'd onto themselves.
264+ file_contents = six .BytesIO (b'a' * (1024 * 1024 * 10 ))
265+ bucket_name = self .create_bucket ()
266+ self .put_object (bucket_name , key_name = 'key.txt' , contents = file_contents )
267+ p = aws ('s3 mv s3://%s/key.txt s3://%s/key.txt' % (bucket_name , bucket_name ))
268+ self .assertEqual (p .rc , 255 )
269+ self .assertIn ('Cannot mv a file onto itself' , p .stderr )
270+
250271
251272class TestRm (BaseS3CLICommand ):
252273 @unittest .skipIf (platform .system () not in ['Darwin' , 'Linux' ],
0 commit comments