[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55147] trunk/blender/source/blender/ blenlib/intern/path_util.c: patch [#34103] path_util_cleanup_path.patch

Campbell Barton ideasman42 at gmail.com
Sun Mar 10 05:43:16 CET 2013


Revision: 55147
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55147
Author:   campbellbarton
Date:     2013-03-10 04:43:15 +0000 (Sun, 10 Mar 2013)
Log Message:
-----------
patch [#34103] path_util_cleanup_path.patch
from Lawrence D'Oliveiro

Improve implementation of BLI_cleanup_path, including making it behave as documented.

"/../home/me" would become "home/me" rather then "/home/me"

Also remove redundant BLI_strncpy()

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/intern/path_util.c

Modified: trunk/blender/source/blender/blenlib/intern/path_util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/path_util.c	2013-03-10 02:30:53 UTC (rev 55146)
+++ trunk/blender/source/blender/blenlib/intern/path_util.c	2013-03-10 04:43:15 UTC (rev 55147)
@@ -362,7 +362,7 @@
 			if (path[2] == '\0') {
 				return; /* path is "//" - cant clean it */
 			}
-			path = path + 2; /* skip the first // */
+			path = path + 2;  /* leave the initial "//" untouched */
 		}
 	}
 	
@@ -414,25 +414,27 @@
 		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(path, "/../", 4) == 0)) {
-		memmove(path, path + 4, strlen(path + 4) + 1);
-	}
-
 	while ( (start = strstr(path, "/../")) ) {
-		eind = start + (4 - 1) /* strlen("/../") - 1 */;
 		a = start - path - 1;
-		while (a > 0) {
-			if (path[a] == '/') break;
-			a--;
+		if (a > 0) {
+			/* <prefix>/<parent>/../<postfix> => <prefix>/<postfix> */
+			eind = start + (4 - 1) /* strlen("/../") - 1 */; /* strip "/.." and keep last "/" */
+			while (a > 0 && path[a] != '/') { /* find start of <parent> */
+				a--;
+			}
+			memmove(path + a, eind, strlen(eind) + 1);
 		}
-		if (a < 0) {
-			break;
-		}
 		else {
-			memmove(path + a, eind, strlen(eind) + 1);
+			/* 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(path, path + 3, strlen(path + 3) + 1);
 		}
 	}
 
@@ -1417,7 +1419,6 @@
 void BLI_make_existing_file(const char *name)
 {
 	char di[FILE_MAX];
-	BLI_strncpy(di, name, sizeof(di));
 	BLI_split_dir_part(name, di, sizeof(di));
 
 	/* make if if the dir doesn't exist */




More information about the Bf-blender-cvs mailing list