Fixed #8455: a lack of permissions in `MEDIA_ROOT` no longer causes an infinite loop when saving files. Thanks, carljm.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8639 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Jacob Kaplan-Moss 2008-08-27 21:44:14 +00:00
parent 52672f2b94
commit f58217cc02
1 changed files with 8 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import os import os
import errno
import urlparse import urlparse
from django.conf import settings from django.conf import settings
@ -161,10 +162,13 @@ class FileSystemStorage(Storage):
finally: finally:
locks.unlock(fd) locks.unlock(fd)
os.close(fd) os.close(fd)
except OSError: except OSError, e:
# Ooops, we need a new file name. if e.errno == errno.EEXIST:
name = self.get_available_name(name) # Ooops, the file exists. We need a new file name.
full_path = self.path(name) name = self.get_available_name(name)
full_path = self.path(name)
else:
raise
else: else:
# OK, the file save worked. Break out of the loop. # OK, the file save worked. Break out of the loop.
break break