Don't truncate files when asked to copy them onto themselves. (bug 767120)
This commit is contained in:
Родитель
118b5ba29e
Коммит
13224ae322
|
@ -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))
|
||||
|
|
Загрузка…
Ссылка в новой задаче