Fixed #18233: Raise IOError if destination file already exists, in django.core.files.move.file_move_safe. #18

Closed
wants to merge 2 commits into from

3 participants

@aviraldg

On certain platforms like Linux, the existing code will simply ignore allow_overwrite and go ahead and overwrite the destination file anyway. This fixes it.

ps. This is also my first contribution to Django :)

@gabrielfalcao

Great work with the individual commit with tests !
👍

@jezdez jezdez commented on the diff May 3, 2012
django/core/files/move.py
@@ -51,6 +51,8 @@ def file_move_safe(old_file_name, new_file_name, chunk_size = 1024*64, allow_ove
return
try:
+ if not allow_overwrite and os.path.exists(new_file_name):
+ raise IOError('Destination file already exists: \'{0}\''.format(new_file_name))
@jezdez
Django member
jezdez added a note May 3, 2012

It's best practice to use common string substitution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@akaariai
Django member

I am closing this pull request as the ticket discussions indicate this isn't 100% ready for commit.

@akaariai akaariai closed this Jul 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment