diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index b9c0dd65ede..0228032df01 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -311,9 +311,9 @@ void BLI_recurdir_fileops(char *dirname) { int BLI_rename(char *from, char *to) { if (!BLI_exists(from)) return 0; - /* refuse to rename if file already exists */ - if (BLI_exists(to)) - return 1; + /* make sure the filenames are different (case insensitive) before removing */ + if (BLI_exists(to) && BLI_strcasecmp(from, to)) + if(BLI_delete(to, 0, 0)) return 1; return rename(from, to); } @@ -391,8 +391,7 @@ void BLI_recurdir_fileops(char *dirname) { int BLI_rename(char *from, char *to) { if (!BLI_exists(from)) return 0; - /* refuse to rename if file already exists */ - if (BLI_exists(to)) return 1; + if (BLI_exists(to)) if(BLI_delete(to, 0, 0)) return 1; return rename(from, to); } diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 1074a24f9ae..e807bad28bf 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -501,6 +501,8 @@ static void renamebutton_cb(bContext *C, void *arg1, char *oldname) char orgname[FILE_MAX+12]; char filename[FILE_MAX+12]; SpaceFile *sfile= (SpaceFile*)CTX_wm_space_data(C); + ARegion* ar = CTX_wm_region(C); + struct direntry *file = (struct direntry *)arg1; BLI_make_file_string(G.sce, orgname, sfile->params->dir, oldname); @@ -508,10 +510,15 @@ static void renamebutton_cb(bContext *C, void *arg1, char *oldname) BLI_make_file_string(G.sce, newname, sfile->params->dir, filename); if( strcmp(orgname, newname) != 0 ) { - BLI_rename(orgname, newname); - - /* to refresh the file list, does sorting again */ - filelist_free(sfile->files); + if (!BLI_exists(newname)) { + BLI_rename(orgname, newname); + /* to make sure we show what is on disk */ + filelist_free(sfile->files); + } else { + BLI_strncpy(file->relname, oldname, strlen(oldname)+1); + } + + ED_region_tag_redraw(ar); } }