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

Function pkgmap_safe_stat

src/pipeline/pass_pkgmap.c:1084–1109  ·  view source on GitHub ↗

Stat a path, skipping symlinks. Returns 0 on success, -1 to skip. * On POSIX, lstat + S_ISLNK avoids following symlink cycles. On Windows * we use the UTF-8-safe wide stat (mirroring discover.c's wide_stat); * reparse points (junctions/symlinks) are detected separately by * pkgmap_is_reparse_point below before we descend. Mirrors discover.c's * safe_stat. */

Source from the content-addressed store, hash-verified

1082 * pkgmap_is_reparse_point below before we descend. Mirrors discover.c's
1083 * safe_stat. */
1084static int pkgmap_safe_stat(const char *abs_path, struct stat *st) {
1085#ifdef _WIN32
1086 wchar_t *wpath = cbm_path_to_wide(abs_path);
1087 if (!wpath) {
1088 return CBM_NOT_FOUND;
1089 }
1090 struct _stat64 wst;
1091 int ret = _wstat64(wpath, &wst);
1092 free(wpath);
1093 if (ret != 0) {
1094 return CBM_NOT_FOUND;
1095 }
1096 st->st_mode = wst.st_mode;
1097 st->st_size = wst.st_size;
1098 st->st_mtime = wst.st_mtime;
1099 return 0;
1100#else
1101 if (lstat(abs_path, st) != 0) {
1102 return CBM_NOT_FOUND;
1103 }
1104 if (S_ISLNK(st->st_mode)) {
1105 return CBM_NOT_FOUND;
1106 }
1107 return 0;
1108#endif
1109}
1110
1111/* True if abs_path is a Windows reparse point (directory junction or
1112 * symlink). Following these is the documented cause of the historic CI

Callers 1

pkgmap_walk_dirFunction · 0.85

Calls 2

cbm_path_to_wideFunction · 0.85
lstatFunction · 0.85

Tested by

no test coverage detected