7a48ee92468a7bb4f778372c37ee2d43186681ff
chmalee
  Wed Mar 12 15:24:09 2025 -0700
Changes from code review, refs #35318

diff --git src/hg/hgHubConnect/trackHubWizard.c src/hg/hgHubConnect/trackHubWizard.c
index bd1eb5d2176..7b56e152e9a 100644
--- src/hg/hgHubConnect/trackHubWizard.c
+++ src/hg/hgHubConnect/trackHubWizard.c
@@ -40,31 +40,34 @@
         {
         fprintf(stderr, "deleting file: '%s'\n", fileName);
         removeFileForUser(fileName, userName);
         fflush(stderr);
         }
     else
         {
         fprintf(stderr, "file '%s' does not exist\n", fileName);
         fflush(stderr);
         }
     }
 }
 
 int pathDepth(char *path)
 {
-return countChars(path, '/');
+// replace multiple occurences of '/' with just a single one to get a canonical path
+// as path///to/file and path/to/file are the same path on Linux
+char *deduped = replaceChars(path, "//", "/");
+return countChars(deduped, '/');
 }
 
 int sortByFullPathCmp(const void *va, const void *vb)
 /* Compare two fullPaths */
 {
 struct jsonElement *a = (struct jsonElement *)(*(struct slRef **)va)->val;
 struct jsonElement *b = (struct jsonElement *)(*(struct slRef **)vb)->val;
 char *aFullpath = jsonStringField(a, "fullPath");
 char *bFullpath = jsonStringField(b, "fullPath");
 int aDepth = pathDepth(aFullpath);
 int bDepth = pathDepth(bFullpath);
 // ensure subdirectories order before their parents:
 if (aDepth != bDepth)
     return bDepth - aDepth;
 // if equal depth than lexicographic sort is fine