Don't truncate files when asked to copy them onto themselves. (bug 767120)

This commit is contained in:
Allen Short 2012-06-22 09:35:48 -05:00
Родитель 118b5ba29e
Коммит 13224ae322
3 изменённых файлов: 18 добавлений и 1 удалений

Просмотреть файл

@ -46,6 +46,8 @@ def copy_stored_file(src_path, dest_path, storage=default_storage,
Each path will be managed by the same storage implementation.
"""
if src_path == dest_path:
return
with storage.open(src_path, 'rb') as src:
with storage.open(dest_path, 'wb') as dest:
done = False

Просмотреть файл

@ -93,6 +93,12 @@ class TestFileOps(unittest.TestCase):
copy_stored_file(src, dest)
eq_(self.contents(dest), '<contents>')
def test_self_copy(self):
src = self.newfile('src.txt', '<contents>')
dest = self.path('src.txt')
copy_stored_file(src, dest)
eq_(self.contents(dest), '<contents>')
def test_move(self):
src = self.newfile('src.txt', '<contents>')
dest = self.path('somedir/dest.txt')

Просмотреть файл

@ -140,7 +140,7 @@ class TestFile(amo.tests.TestCase, amo.tests.AMOPaths):
assert hide_mock.called
@mock.patch('files.models.File.unhide_disabled_file')
def test_unhide_disabled_file(self, unhide_mock):
def test_unhide_on_enable(self, unhide_mock):
f = File.objects.get(pk=67442)
f.status = amo.STATUS_PUBLIC
f.save()
@ -156,6 +156,15 @@ class TestFile(amo.tests.TestCase, amo.tests.AMOPaths):
f.save()
assert unhide_mock.called
def test_unhide_disabled_files(self):
f = File.objects.get(pk=67442)
f.status = amo.STATUS_PUBLIC
with storage.open(f.guarded_file_path, 'wb') as fp:
fp.write('some data\n')
f.unhide_disabled_file()
assert storage.exists(f.file_path)
assert storage.open(f.file_path).size
def test_unhide_disabled_file_mirroring(self):
tmp = tempfile.mkdtemp()
self.addCleanup(lambda: shutil.rmtree(tmp))