On Thu Feb 6 13:12:41 2025 +0000, Jinoh Kang wrote:
There is probably no fundamental improvements in I/O aspect, although I believe the name `is_same_dentry` is much clearer. I like this version better:
/* Determine if two paths have the same parent directories and basenames. */ static int is_same_dentry( const char *pathname1, const char *pathname2 ) { const char *lastslash1 = strrchr(pathname1, '/'); const char *lastslash2 = strrchr(pathname2, '/'); char *dirname1 = NULL, dirname2 = NULL; int res; /* Last slash must be preceded by a non-slash character */ assert( lastslash1 && lastslash1 != pathname1 && lastslash1[-1] != '/' ); assert( lastslash2 && lastslash2 != pathname2 && lastslash2[-1] != '/' ); /* different basenames imply different dentries */ if (strcmp( lastslash1 + 1, lastslash2 + 1 ) != 0) return 0; res = -1; if ((dirname1 = memdup( pathname1, lastslash1 + 1 - pathname1 )) && (dirname2 = memdup( pathname2, lastslash2 + 1 - pathname2 ))) { struct stat st1, st2; dirname1[lastslash1 - pathname1] = '\0'; dirname2[lastslash2 - pathname2] = '\0'; if (stat(dirname1, &st1) || stat(dirname2, &st2)) { file_set_error(); } else { res = st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino; } } free(dirname2); free(dirname1); return res; }
Are you sure that "name" (I mean the one passed to the function) can't have trailing slashes or multiple of them? I somehow remember it was a possible concern at some point long ago when the other case-insens patchset got reviewed by Rémi, but not sure anymore.