From 6f7650041c26fcaf3a55e973b26b0619b65a5747 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Thu, 20 Apr 2023 17:13:50 +0200 Subject: [PATCH 1/2] Use shutil.move instead of shutil.copy2 to speed up store large files The OS should prefer to rename in this case if source and destination are on the same file system. --- django_drf_filepond/api.py | 2 +- tests/test_api.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/django_drf_filepond/api.py b/django_drf_filepond/api.py index dd6dfd3..c096312 100644 --- a/django_drf_filepond/api.py +++ b/django_drf_filepond/api.py @@ -164,7 +164,7 @@ def _store_upload_local(destination_file_path, destination_file_name, try: if not os.path.exists(target_dir): os.makedirs(target_dir) - shutil.copy2(temp_upload.get_file_path(), target_file_path) + shutil.move(temp_upload.get_file_path(), target_file_path) su.save() temp_upload.delete() except IOError as e: diff --git a/tests/test_api.py b/tests/test_api.py index af801f2..9e77011 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -335,12 +335,12 @@ def test_store_upload_local_direct_file_exists(self): def test_store_upload_local_copy_to_store_fails(self): tu = TemporaryUpload.objects.get(upload_id=self.upload_id) - with patch('shutil.copy2') as copy2_patch: + with patch('shutil.move') as move_patch: with patch('os.path.exists') as exists_patch: with patch('os.path.isdir') as isdir_patch: exists_patch.side_effect = [True, False, True] isdir_patch.return_value = True - copy2_patch.side_effect = IOError( + move_patch.side_effect = IOError( 'Error moving temporary file to permanent storage ' 'location') with self.assertRaisesMessage( From 1b7b802d8b1a33d0a1ad3690f3a144bac869cac3 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Wed, 19 Apr 2023 10:05:01 +0200 Subject: [PATCH 2/2] Added copyright notice for change. --- LICENSE | 1 + 1 file changed, 1 insertion(+) diff --git a/LICENSE b/LICENSE index 3a099ae..0d849d1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ BSD 3-Clause License Copyright (c) 2018, Jeremy Cohen, Imperial College London + 2023, Equinor ASA All rights reserved. Redistribution and use in source and binary forms, with or without