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

Function safe_stat

src/discover/discover.c:910–933  ·  view source on GitHub ↗

Stat a path, skipping symlinks (POSIX) and junctions / reparse points * (Windows). Returns 0 on success, -1 to skip. Skipping reparse points keeps * discovery from walking through a junction that points outside the project * root, mirroring the POSIX S_ISLNK skip. *is_symlink reports whether the * skip (if any) was specifically the symlink/reparse-point check, as * opposed to some other stat

Source from the content-addressed store, hash-verified

908 * skip (if any) was specifically the symlink/reparse-point check, as
909 * opposed to some other stat failure (permissions, a race with a delete). */
910static int safe_stat(const char *abs_path, struct stat *st, bool *is_symlink) {
911 *is_symlink = false;
912#ifdef _WIN32
913 wchar_t *wpath = cbm_path_to_wide(abs_path);
914 if (wpath) {
915 DWORD attr = GetFileAttributesW(wpath);
916 free(wpath);
917 if (attr != INVALID_FILE_ATTRIBUTES && (attr & FILE_ATTRIBUTE_REPARSE_POINT)) {
918 *is_symlink = true;
919 return CBM_NOT_FOUND;
920 }
921 }
922 return wide_stat(abs_path, st);
923#else
924 if (lstat(abs_path, st) != 0) {
925 return CBM_NOT_FOUND;
926 }
927 if (S_ISLNK(st->st_mode)) {
928 *is_symlink = true;
929 return CBM_NOT_FOUND;
930 }
931 return 0;
932#endif
933}
934
935/* ── Sphinx documentation sets ────────────────────────────────────
936 * A directory with a conf.py is a Sphinx documentation set, and its

Callers 1

walk_dir_process_entryFunction · 0.85

Calls 3

cbm_path_to_wideFunction · 0.85
wide_statFunction · 0.85
lstatFunction · 0.85

Tested by

no test coverage detected