[Bf-blender-cvs] [661b01825f8] master: Fix for recent commit removing slashes

Campbell Barton noreply at git.blender.org
Wed Feb 26 11:37:56 CET 2020


Commit: 661b01825f811e949feae5ade8170efe09a716c2
Author: Campbell Barton
Date:   Wed Feb 26 21:34:45 2020 +1100
Branches: master
https://developer.blender.org/rB661b01825f811e949feae5ade8170efe09a716c2

Fix for recent commit removing slashes

The slashed were used for comparing bookmarks to the current directory.

Add trailing slashes in 'fsmenu_insert_entry',
which avoids having to duplicate strings just to add a slash
before passing to this function.

===================================================================

M	source/blender/editors/space_file/fsmenu.c

===================================================================

diff --git a/source/blender/editors/space_file/fsmenu.c b/source/blender/editors/space_file/fsmenu.c
index 1fbc07c7a5d..daa3495b1c4 100644
--- a/source/blender/editors/space_file/fsmenu.c
+++ b/source/blender/editors/space_file/fsmenu.c
@@ -380,6 +380,12 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu,
                          int icon,
                          FSMenuInsert flag)
 {
+  const uint path_len = strlen(path);
+  BLI_assert(path_len > 0);
+  if (path_len == 0) {
+    return;
+  }
+  const bool has_trailing_slash = (path[path_len - 1] == SEP);
   FSMenuEntry *fsm_prev;
   FSMenuEntry *fsm_iter;
   FSMenuEntry *fsm_head;
@@ -389,8 +395,9 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu,
 
   for (fsm_iter = fsm_head; fsm_iter; fsm_prev = fsm_iter, fsm_iter = fsm_iter->next) {
     if (fsm_iter->path) {
-      const int cmp_ret = BLI_path_cmp(path, fsm_iter->path);
-      if (cmp_ret == 0) {
+      /* Compare, with/without the trailing slash in 'path'. */
+      const int cmp_ret = BLI_path_ncmp(path, fsm_iter->path, path_len);
+      if (cmp_ret == 0 && STREQ(fsm_iter->path + path_len, has_trailing_slash ? "" : SEP_STR)) {
         if (flag & FS_INSERT_FIRST) {
           if (fsm_iter != fsm_head) {
             fsm_prev->next = fsm_iter->next;
@@ -415,7 +422,14 @@ void fsmenu_insert_entry(struct FSMenu *fsmenu,
   }
 
   fsm_iter = MEM_mallocN(sizeof(*fsm_iter), "fsme");
-  fsm_iter->path = BLI_strdup(path);
+  if (has_trailing_slash) {
+    fsm_iter->path = BLI_strdup(path);
+  }
+  else {
+    fsm_iter->path = BLI_strdupn(path, path_len + 1);
+    fsm_iter->path[path_len] = SEP;
+    fsm_iter->path[path_len + 1] = '\0';
+  }
   fsm_iter->save = (flag & FS_INSERT_SAVE) != 0;
 
   /* If entry is also in another list, use that icon and maybe name. */
@@ -608,7 +622,6 @@ static void fsmenu_add_windows_folder(struct FSMenu *fsmenu,
   if (SHGetKnownFolderPath(rfid, 0, NULL, &pPath) == S_OK) {
     BLI_strncpy_wchar_as_utf8(line, pPath, FILE_MAXDIR);
     CoTaskMemFree(pPath);
-    BLI_add_slash(line);
     fsmenu_insert_entry(fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, name, icon, flag);
   }
 }
@@ -745,9 +758,6 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
         CFRelease(localKey);
       }
 
-      /* Add end slash for consistency with other platforms */
-      BLI_add_slash(defPath);
-
       fsmenu_insert_entry(
           fsmenu, FS_CATEGORY_SYSTEM, defPath, name[0] ? name : NULL, icon, FS_INSERT_SORTED);
     }
@@ -786,9 +796,6 @@ void fsmenu_read_system(struct FSMenu *fsmenu, int read_bookmarks)
         /* Exclude "all my files" as it makes no sense in blender fileselector */
         /* Exclude "airdrop" if wlan not active as it would show "" ) */
         if (!strstr(line, "myDocuments.cannedSearch") && (*line != '\0')) {
-          /* Add end slash for consistency with other platforms */
-          BLI_add_slash(line);
-
           fsmenu_insert_entry(
               fsmenu, FS_CATEGORY_SYSTEM_BOOKMARKS, line, NULL, ICON_FILE_FOLDER, FS_INSERT_LAST);
         }



More information about the Bf-blender-cvs mailing list