1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #9610 -- Fixed duplicate uploaded file name mangling when directory contained a dot and file didn't. Based on patches from fadlytabrani and adurdin.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10701 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Gary Wilson Jr
2009-05-08 05:50:31 +00:00
parent 304785bf26
commit 59507753c7
2 changed files with 51 additions and 12 deletions

View File

@@ -63,15 +63,15 @@ class Storage(object):
Returns a filename that's free on the target storage system, and
available for new content to be written to.
"""
# If the filename already exists, keep adding an underscore to the name
# of the file until the filename doesn't exist.
dir_name, file_name = os.path.split(name)
file_root, file_ext = os.path.splitext(file_name)
# If the filename already exists, keep adding an underscore (before the
# file extension, if one exists) to the filename until the generated
# filename doesn't exist.
while self.exists(name):
try:
dot_index = name.rindex('.')
except ValueError: # filename has no dot
name += '_'
else:
name = name[:dot_index] + '_' + name[dot_index:]
file_root += '_'
# file_ext includes the dot.
name = os.path.join(dir_name, file_root + file_ext)
return name
def path(self, name):