Page MenuHome

FIX for #20256 New folder doesn't rename
Closed, ArchivedPublicPATCH

Description

A rather simple fix, tho the code there was quite confusing. Renaming is triggered by assigning the name of the file to be renamed to sfile->params->renamefile. This was only done, if a filed named "New Folder" already existed. Otherwise a non initialized buffer was copied to sfile->params->renamefile.

hope that helps, Aurel

Event Timeline

Unless I'm missing something, wouldn't it be easier if you just changed
BLI_strncpy(tmpstr, sfile->params->dir, FILE_MAX);
to
BLI_strncpy(tmpdir, sfile->params->dir, FILE_MAX);

and the next line to
BLI_join_dirfile(tmpstr, tmpdir, "New Folder")


(Disclaimer: untested code changes...)


----------

Assigning to Elubie (file browser maintainer)

The code there is a bit confusing, sfile->params->dir returns the path of the "working directory", or the active path shown in the file browser. tmpdir however is the name of the new created directory within the active directory.

Example:
BLI_strncpy(tmpstr, sfile->params->dir, FILE_MAX);
tmpstr == /foo/bar/
tmpdir == NewFolder
BLI_join_dirfile(tmpstr, tmpstr, tmpdir);
tmpstr == /foo/bar/NewFolder
tmpdir == NewFolder

tmpstr: "/foo/bar/NewFolder" is needed to create the directory in the file system
tmpdir: "NewFolder" is assigned to sfile->params->renamefile and on the next redraw (or whatever event) that will trigger renaming of the file or directory "NewFolder" in the directory which is currently displayed.

So just initializing:
char tmpdir[FILE_MAXFILE] = "New Folder";
and then using it directly, rather than another constant:
BLI_join_dirfile(tmpstr, tmpstr, tmpdir);
is the right way to do it.

Grief... that is totally confusing and non-obvious from the variable names, etc.

True, it took me some time too to see what's going on. I could have refactroed and commented that function too, but i was criticized in past for mixing this with a simple bug fix. Anyway,... applying this should be fine.

Thanks Aurel for submitting the patch. Was actual bug, and you guys were also right about the naming ;) - I have refactored the code in this area a bit and applied your solution, hopefully a bit more readable now.

Committed in rev. 25195

Andrea Weikert (elubie) changed the task status from Unknown Status to Unknown Status.Dec 8 2009, 12:53 AM