Ticket #9610: 9610.diff
File 9610.diff, 2.2 KB (added by , 16 years ago) |
---|
-
django/core/files/storage.py
63 63 Returns a filename that's free on the target storage system, and 64 64 available for new content to be written to. 65 65 """ 66 67 dir_name, file_name = os.path.split(name) 66 68 # If the filename already exists, keep adding an underscore to the name 67 69 # of the file until the filename doesn't exist. 68 70 while self.exists(name): 69 71 try: 70 dot_index = name.rindex('.')72 dot_index = file_name.rindex('.') 71 73 except ValueError: # filename has no dot 72 name += '_'74 file_name += '_' 73 75 else: 74 name = name[:dot_index] + '_' + name[dot_index:] 76 file_name = file_name[:dot_index] + '_' + file_name[dot_index:] 77 name = os.path.join(dir_name, file_name) 75 78 return name 76 79 77 80 def path(self, name): -
tests/regressiontests/file_storage/tests.py
141 141 actual_mode = os.stat(self.storage.path(name))[0] & 0777 142 142 self.assertEqual(actual_mode, 0666) 143 143 144 145 class FileStorageDirectoryNameParsing(TestCase): 146 """Regression test for #9610: Using a dotted pathname would mangle 147 the directory name instead of the filename if the file already 148 existed.""" 149 def setUp(self): 150 self.storage_dir = tempfile.mkdtemp() 151 self.storage = FileSystemStorage(self.storage_dir) 152 153 def tearDown(self): 154 shutil.rmtree(self.storage_dir) 155 156 def test_directory_name_parsing(self): 157 self.storage.save('dotted.path/test', ContentFile("1")) 158 self.storage.save('dotted.path/test', ContentFile("2")) 159 160 self.assertFalse(os.path.exists(os.path.join(self.storage_dir, 'dotted_.path'))) 161 self.assertTrue(os.path.exists(os.path.join(self.storage_dir, 'dotted.path/test_')))