﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
9610	File upload duplicate filename check mechanism fail	fadlytabrani	fadlytabrani	"The file upload duplicate filename check mechanism will fail if the upload directory contains a dot and when the filename does not.

django.core.files.storage:Storage

{{{
def get_available_name(self, name):
        """"""
        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.
        while self.exists(name):
            try:
                dot_index = name.rindex('.')
            except ValueError: # filename has no dot
                name += '_'
            else:
                name = name[:dot_index] + '_' + name[dot_index:]
        return name

# Failure example, uploading duplicate file ""testlog"" will create new directory upload_.10122008
# Correct result would be ""testlog"" would be uploaded with the filename testlog_
get_available_name(""c:\\django\\media\\upload.10122008\\testlog"")
}}}

Using os.path would solve the problem

{{{
def get_available_name(self, name):
        while self.exists(name):
            dname, fname = os.path.split(name)
            try:
                dot_index = fname.rindex('.')
            except ValueError:
                fname += '_'
            else:
                fname = fname[:dot_index] + '_' + fname[dot_index:]
                
            return os.path.join(dname, fname)
}}}"		closed	File uploads/storage	1.0		fixed			Ready for checkin	1	0	0	0	0	0
