Page MenuHome

path_util_cleanup_path.patch

path_util_cleanup_path.patch

commit 28bf1b51cd75746f69b4580c01fee1236910f783
Author: Lawrence D'Oliveiro <ldo@geek-central.gen.nz>
Date: Thu Feb 14 03:36:25 2013 +0000
Improve implementation of BLI_cleanup_path, including making it behave as documented
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index ff0b486..a90cad6 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -350,7 +350,7 @@ void BLI_cleanup_path(const char *relabase, char *dir)
if (dir[2] == '\0') {
return; /* path is "//" - cant clean it */
}
- dir = dir + 2; /* skip the first // */
+ dir = dir + 2; /* leave the initial "//" untouched */
}
}
@@ -402,26 +402,29 @@ void BLI_cleanup_path(const char *relabase, char *dir)
return;
}
- /* support for odd paths: eg /../home/me --> /home/me
- * this is a valid path in blender but we cant handle this the usual way below
- * simply strip this prefix then evaluate the path as usual. 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 + (4 - 1) /* strlen("/../") - 1 */;
a = start - dir - 1;
- while (a > 0) {
- if (dir[a] == '/') break;
- a--;
- }
- if (a < 0) {
- break;
- }
- else {
+ if (a > 0)
+ {
+ /* <prefix>/<parent>/../<postfix> => <prefix>/<postfix> */
+ eind = start + (4 - 1) /* strlen("/../") - 1 */; /* strip "/.." and keep last "/" */
+ while (a > 0 && dir[a] != '/') { /* find start of <parent> */
+ a--;
+ }
memmove(dir + a, eind, strlen(eind) + 1);
- }
+ }
+ else
+ {
+ /* support for odd paths: eg /../home/me --> /home/me
+ * this is a valid path in blender but we cant handle this the usual way below
+ * simply strip this prefix then evaluate the path as usual.
+ * pythons os.path.normpath() does this */
+ /* Note: previous version of following call used an offset of 3 instead of 4,
+ which meant that the "/../home/me" example actually became "home/me".
+ Using offset of 3 gives behaviour consistent with the abovementioned
+ Python routine. */
+ memmove(dir, dir + 3, strlen(dir + 3) + 1);
+ } /*if*/
}
while ( (start = strstr(dir, "/./")) ) {

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
9a/52/628a72f35cf939af4f650f55fc01

Event Timeline