Write the FULL (uncapped) skip list to a per-run logfile — ONLY when >=1 file * was skipped (no logfile on a clean run). Location: * $CBM_INDEX_LOG (override) else /logs/ - .log * Returns true and fills out_path on success. */
| 11055 | * $CBM_INDEX_LOG (override) else <cache_dir>/logs/<project>-<epoch>.log |
| 11056 | * Returns true and fills out_path on success. */ |
| 11057 | static bool write_skip_logfile(const char *project, const cbm_file_error_t *errs, int count, |
| 11058 | char *out_path, size_t out_sz) { |
| 11059 | if (!errs || count <= 0) { |
| 11060 | return false; |
| 11061 | } |
| 11062 | char path[CBM_SZ_1K]; |
| 11063 | const char *override = getenv("CBM_INDEX_LOG"); |
| 11064 | if (override && override[0]) { |
| 11065 | /* An override that does not fit is cut off into another file's name, |
| 11066 | * and "wb" would create or truncate that file: no logfile then. */ |
| 11067 | int written = snprintf(path, sizeof(path), "%s", override); |
| 11068 | if (written <= 0 || (size_t)written >= sizeof(path)) { |
| 11069 | cbm_log_warn("index.logfile_path_too_long", "source", "CBM_INDEX_LOG"); |
| 11070 | return false; |
| 11071 | } |
| 11072 | } else { |
| 11073 | const char *cdir = cbm_resolve_cache_dir(); |
| 11074 | if (!cdir) { |
| 11075 | return false; |
| 11076 | } |
| 11077 | char logdir[CBM_SZ_1K]; |
| 11078 | snprintf(logdir, sizeof(logdir), "%s/logs", cdir); |
| 11079 | cbm_mkdir_p_ex(logdir, 0755, CBM_MKDIR_FOLLOW_OWNED); |
| 11080 | snprintf(path, sizeof(path), "%s/%s-%lld.log", logdir, project ? project : "index", |
| 11081 | (long long)time(NULL)); |
| 11082 | } |
| 11083 | FILE *f = cbm_fopen(path, "wb"); |
| 11084 | if (!f) { |
| 11085 | cbm_log_warn("index.logfile_open_fail", "path", path); |
| 11086 | return false; |
| 11087 | } |
| 11088 | int partials = 0; |
| 11089 | for (int i = 0; i < count; i++) { |
| 11090 | if (is_parse_partial(&errs[i])) { |
| 11091 | partials++; |
| 11092 | } |
| 11093 | } |
| 11094 | (void)fprintf(f, "# codebase-memory-mcp index coverage report\n"); |
| 11095 | (void)fprintf(f, "# project=%s skipped=%d parse_partial=%d\n", project ? project : "", |
| 11096 | count - partials, partials); |
| 11097 | (void)fprintf(f, "# columns: phase\treason\tpath\n"); |
| 11098 | for (int i = 0; i < count; i++) { |
| 11099 | (void)fprintf(f, "%s\t%s\t%s\n", errs[i].phase ? errs[i].phase : "", |
| 11100 | errs[i].reason ? errs[i].reason : "", errs[i].path ? errs[i].path : ""); |
| 11101 | } |
| 11102 | (void)fclose(f); |
| 11103 | if (out_path && out_sz) { |
| 11104 | snprintf(out_path, out_sz, "%s", path); |
| 11105 | } |
| 11106 | return true; |
| 11107 | } |
| 11108 | |
| 11109 | /* Build the success portion of the index_repository response. |
| 11110 | * Returns true when status should be "degraded" (#334 plausibility gate). */ |
no test coverage detected