* python sys.cleanpath() used strstr incorrectly, resulting in paths containing a slash, always returning a path that ends with a slash.

* python Blender.GetPaths() - absolute=0 wasnt working
* BLI_cleanup_file and BLI_cleanup_file were treating the // prefix as a duplicate path, now ignores //
* BLI_convertstringcode was removing the trailing slash from a path
(tested these path functions didnt mess up with some of the peach files and with pointcache)
This commit is contained in:
Campbell Barton 2008-06-05 13:02:00 +00:00
parent cc0d730923
commit 4f601b478c
3 changed files with 28 additions and 17 deletions

@ -865,11 +865,8 @@ int BLI_strcaseeq(char *a, char *b) {
void BLI_cleanup_dir(const char *relabase, char *dir) void BLI_cleanup_dir(const char *relabase, char *dir)
{ {
BLI_cleanup_file(relabase, dir); BLI_cleanup_file(relabase, dir);
#ifdef WIN32 BLI_add_slash(dir);
strcat(dir, "\\");
#else
strcat(dir, "/");
#endif
} }
void BLI_cleanup_file(const char *relabase, char *dir) void BLI_cleanup_file(const char *relabase, char *dir)
@ -878,6 +875,13 @@ void BLI_cleanup_file(const char *relabase, char *dir)
char *start, *eind; char *start, *eind;
if (relabase) { if (relabase) {
BLI_convertstringcode(dir, relabase); BLI_convertstringcode(dir, relabase);
} else {
if (dir[0]=='/' && dir[1]=='/') {
if (dir[2]== '\0') {
return; /* path is "//" - cant clean it */
}
dir = dir+2; /* skip the first // */
}
} }
#ifdef WIN32 #ifdef WIN32
if(dir[0]=='.') { /* happens for example in FILE_MAIN */ if(dir[0]=='.') { /* happens for example in FILE_MAIN */
@ -1150,24 +1154,30 @@ int BLI_convertstringcode(char *path, const char *basepath)
BLI_char_switch(tmp, '\\', '/'); BLI_char_switch(tmp, '\\', '/');
BLI_char_switch(base, '\\', '/'); BLI_char_switch(base, '\\', '/');
/* Paths starting with // will get the blend file as their base,
* this isnt standard in any os but is uesed in blender all over the place */
if (tmp[0] == '/' && tmp[1] == '/') { if (tmp[0] == '/' && tmp[1] == '/') {
char *filepart= BLI_strdup(tmp+2); /* skip code */
char *lslash= BLI_last_slash(base); char *lslash= BLI_last_slash(base);
if (lslash) { if (lslash) {
int baselen= (int) (lslash-base) + 1; int baselen= (int) (lslash-base) + 1;
/* use path for for temp storage here, we copy back over it right away */
BLI_strncpy(path, tmp+2, FILE_MAX);
memcpy(tmp, base, baselen); memcpy(tmp, base, baselen);
strcpy(tmp+baselen, filepart); strcpy(tmp+baselen, path);
} else {
strcpy(tmp, filepart);
}
MEM_freeN(filepart);
}
BLI_cleanup_file(NULL, tmp);
strcpy(path, tmp); strcpy(path, tmp);
} else {
strcpy(path, tmp+2);
}
} else {
strcpy(path, tmp);
}
if (path[strlen(path)-1]=='/') {
BLI_cleanup_dir(NULL, path);
} else {
BLI_cleanup_file(NULL, path);
}
#ifdef WIN32 #ifdef WIN32
/* skip first two chars, which in case of /* skip first two chars, which in case of

@ -952,7 +952,7 @@ static PyObject *Blender_GetPaths( PyObject * self, PyObject *args, PyObject *ke
if (absolute) { if (absolute) {
BLI_bpathIterator_getPathExpanded( &bpi, filepath_expanded ); BLI_bpathIterator_getPathExpanded( &bpi, filepath_expanded );
} else { } else {
BLI_bpathIterator_getPathExpanded( &bpi, filepath_expanded ); BLI_bpathIterator_getPath( &bpi, filepath_expanded );
} }
st = PyString_FromString(filepath_expanded); st = PyString_FromString(filepath_expanded);

@ -406,11 +406,12 @@ static PyObject *M_sys_cleanpath( PyObject * self, PyObject * value )
{ {
char *path = PyString_AsString(value); char *path = PyString_AsString(value);
char cleaned[FILE_MAXDIR + FILE_MAXFILE]; char cleaned[FILE_MAXDIR + FILE_MAXFILE];
int trailing_slash = 0; int trailing_slash = 0, last;
if (!path) if (!path)
return EXPP_ReturnPyObjError( PyExc_TypeError, return EXPP_ReturnPyObjError( PyExc_TypeError,
"expected string argument" ); "expected string argument" );
if (strstr(path, "/") || strstr(path, "\\")) { last = strlen(path)-1;
if ((path[last]=='/') || (path[last]=='\\')) {
trailing_slash = 1; trailing_slash = 1;
} }
BLI_strncpy(cleaned, path, FILE_MAXDIR + FILE_MAXFILE); BLI_strncpy(cleaned, path, FILE_MAXDIR + FILE_MAXFILE);