Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shutil.move instead of copy2 to move files to local storage #93

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion django_drf_filepond/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down