MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_same_file

Function cbm_same_file

src/cli/cli.c:1065–1083  ·  view source on GitHub ↗

Return true if two paths refer to the same on-disk file. Used to avoid * copying the running binary onto itself during install (cbm_copy_file would * truncate it, since it opens the destination "wb" before reading the source). */

Source from the content-addressed store, hash-verified

1063 * copying the running binary onto itself during install (cbm_copy_file would
1064 * truncate it, since it opens the destination "wb" before reading the source). */
1065static bool cbm_same_file(const char *a, const char *b) {
1066 struct stat sa;
1067 struct stat sb;
1068 if (stat(a, &sa) != 0 || stat(b, &sb) != 0) {
1069 return false;
1070 }
1071#ifdef _WIN32
1072 /* st_ino is unreliable on Windows; compare normalized path strings. */
1073 char na[CLI_BUF_1K];
1074 char nb[CLI_BUF_1K];
1075 snprintf(na, sizeof(na), "%s", a);
1076 snprintf(nb, sizeof(nb), "%s", b);
1077 cbm_normalize_path_sep(na);
1078 cbm_normalize_path_sep(nb);
1079 return strcmp(na, nb) == 0;
1080#else
1081 return sa.st_dev == sb.st_dev && sa.st_ino == sb.st_ino;
1082#endif
1083}
1084
1085typedef struct {
1086 char fingerprint[CBM_DAEMON_BUILD_FINGERPRINT_SIZE];

Callers 2

cbm_cmd_installFunction · 0.85

Calls 2

cbm_normalize_path_sepFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected