bugfix [#23783] /../ prefix stops going up a dir

also fix for recent addition to operator check(), when the file selector is loaded with no operator.
This commit is contained in:
Campbell Barton
2010-09-17 15:11:12 +00:00
parent 84dc5a3b94
commit 6717b75ecd
2 changed files with 31 additions and 20 deletions

View File

@@ -311,10 +311,17 @@ void BLI_cleanup_file(const char *relabase, char *dir)
dir[0]= '/';
dir[1]= 0;
return;
}
}
/* support for odd paths: eg /../home/me --> /home/me
* this is a valid path in blender but we cant handle this the useual way below
* simply strip this prefix then evaluate the path as useual. pythons os.path.normpath() does this */
while((strncmp(dir, "/../", 4)==0)) {
memmove( dir, dir + 4, strlen(dir + 4) + 1 );
}
while ( (start = strstr(dir, "/../")) ) {
eind = start + strlen("/../") - 1;
eind = start + (4 - 1) /* strlen("/../") - 1 */;
a = start-dir-1;
while (a>0) {
if (dir[a] == '/') break;
@@ -328,12 +335,12 @@ void BLI_cleanup_file(const char *relabase, char *dir)
}
while ( (start = strstr(dir,"/./")) ){
eind = start + strlen("/./") - 1;
eind = start + (3 - 1) /* strlen("/./") - 1 */;
memmove( start, eind, strlen(eind)+1 );
}
while ( (start = strstr(dir,"//" )) ){
eind = start + strlen("//") - 1;
eind = start + (2 - 1) /* strlen("//") - 1 */;
memmove( start, eind, strlen(eind)+1 );
}

View File

@@ -624,28 +624,32 @@ void file_draw_check_cb(bContext *C, void *dummy1, void *dummy2)
{
SpaceFile *sfile= CTX_wm_space_file(C);
wmOperator *op= sfile->op;
if(op->type->check) {
char filepath[FILE_MAX];
file_sfile_to_operator(op, sfile, filepath);
/* redraw */
if(op->type->check(C, op)) {
file_operator_to_sfile(sfile, op);
/* redraw, else the changed settings wont get updated */
ED_area_tag_redraw(CTX_wm_area(C));
if(op) { /* fail on reload */
if(op->type->check) {
char filepath[FILE_MAX];
file_sfile_to_operator(op, sfile, filepath);
/* redraw */
if(op->type->check(C, op)) {
file_operator_to_sfile(sfile, op);
/* redraw, else the changed settings wont get updated */
ED_area_tag_redraw(CTX_wm_area(C));
}
}
}
}
int file_draw_check_exists(SpaceFile *sfile)
{
if(RNA_struct_find_property(sfile->op->ptr, "check_existing")) {
if(RNA_boolean_get(sfile->op->ptr, "check_existing")) {
char filepath[FILE_MAX];
BLI_join_dirfile(filepath, sfile->params->dir, sfile->params->file);
if(BLI_exists(filepath) && !BLI_is_dir(filepath)) {
return TRUE;
if(sfile->op) { /* fails on reload */
if(RNA_struct_find_property(sfile->op->ptr, "check_existing")) {
if(RNA_boolean_get(sfile->op->ptr, "check_existing")) {
char filepath[FILE_MAX];
BLI_join_dirfile(filepath, sfile->params->dir, sfile->params->file);
if(BLI_exists(filepath) && !BLI_is_dir(filepath)) {
return TRUE;
}
}
}
}