diff --git a/AUTHORS b/AUTHORS
index e3aec98..526f355 100644
a
|
b
|
answer newbie questions, and generally made Django that much better:
|
563 | 563 | Gasper Zejn <zejn@kiberpipa.org> |
564 | 564 | Jarek Zgoda <jarek.zgoda@gmail.com> |
565 | 565 | Cheng Zhang |
| 566 | Aviral Dasgupta <aviraldg@gmail.com> |
566 | 567 | |
567 | 568 | A big THANK YOU goes to: |
568 | 569 | |
diff --git a/django/core/files/move.py b/django/core/files/move.py
index 3349fc2..4681e00 100644
a
|
b
|
def file_move_safe(old_file_name, new_file_name, chunk_size = 1024*64, allow_ove
|
51 | 51 | return |
52 | 52 | |
53 | 53 | try: |
| 54 | if not allow_overwrite and os.path.exists(new_file_name): |
| 55 | raise IOError('Destination file already exists: \'{0}\''.format(new_file_name)) |
54 | 56 | os.rename(old_file_name, new_file_name) |
55 | 57 | return |
56 | 58 | except OSError: |
diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
index c28b019..f607b83 100644
a
|
b
|
from django.core.files.base import File, ContentFile
|
23 | 23 | from django.core.files.images import get_image_dimensions |
24 | 24 | from django.core.files.storage import FileSystemStorage, get_storage_class |
25 | 25 | from django.core.files.uploadedfile import UploadedFile |
| 26 | from django.core.files.move import file_move_safe |
26 | 27 | from django.test import SimpleTestCase |
27 | 28 | from django.utils import unittest |
28 | 29 | from ..servers.tests import LiveServerBase |
… |
… |
class FileLikeObjectTestCase(LiveServerBase):
|
586 | 587 | remote_file = self.urlopen('/example_view/') |
587 | 588 | |
588 | 589 | self.assertEqual(stored_file.read(), remote_file.read()) |
| 590 | |
| 591 | class MoveTestCase(unittest.TestCase): |
| 592 | """ |
| 593 | Test django.core.files.move. |
| 594 | """ |
| 595 | def setUp(self): |
| 596 | self.file_a = tempfile.mkstemp() |
| 597 | self.file_b = tempfile.mkstemp() |
| 598 | |
| 599 | def tearDown(self): |
| 600 | os.close(self.file_a[0]) |
| 601 | os.close(self.file_b[0]) |
| 602 | os.remove(self.file_a[1]) |
| 603 | os.remove(self.file_b[1]) |
| 604 | |
| 605 | def test_overwrite_existing_file(self): |
| 606 | """ |
| 607 | Test that file_move_safe raises an IOError if you try to overwrite an |
| 608 | existing file without passing in allow_overwrite=True. |
| 609 | """ |
| 610 | self.assertRaises(IOError, file_move_safe, self.file_a[1], self.file_b[1]) |