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

Function poll_project

src/watcher/watcher.c:1595–1710  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1593}
1594
1595static void poll_project(const char *key, void *val, void *ud) {
1596 (void)key;
1597 poll_ctx_t *ctx = ud;
1598 project_state_t *s = val;
1599 if (!s || !atomic_load_explicit(&s->registered, memory_order_acquire)) {
1600 return;
1601 }
1602
1603 /* Stale-root pruning (#286): classify the root BEFORE the baseline /
1604 * is_git / interval gates so vanished roots are noticed even for
1605 * non-git projects and regardless of adaptive backoff. */
1606 int stat_errno = 0;
1607 root_status_t rs = root_status(s->root_path, &stat_errno);
1608 if (rs == ROOT_UNCERTAIN) {
1609 /* EACCES / EIO / network blip / TCC revocation — the root may still
1610 * exist. Never count toward pruning; restart the streak so only an
1611 * uninterrupted run of genuine ENOENT/ENOTDIR observations can
1612 * delete user data. */
1613 if (s->missing_root_count > 0) {
1614 s->missing_root_count = 0;
1615 s->first_missing_ms = 0;
1616 }
1617 cbm_log_warn("watcher.root_stat_error", "project", s->project_name, "path", s->root_path,
1618 "errno", itoa_buf(stat_errno));
1619 return;
1620 }
1621 if (rs == ROOT_MISSING) {
1622 uint64_t now_ms = cbm_now_ms();
1623 if (s->missing_root_count == 0) {
1624 s->first_missing_ms = now_ms;
1625 }
1626 s->missing_root_count++;
1627 cbm_log_warn("watcher.root_missing", "project", s->project_name, "path", s->root_path,
1628 "polls", itoa_buf(s->missing_root_count));
1629 if (s->missing_root_count >= MISSING_ROOT_DELETE_AFTER &&
1630 now_ms - s->first_missing_ms >= (uint64_t)prune_grace_s() * CBM_MSEC_PER_SEC) {
1631 prune_missing_project(ctx->w, s);
1632 }
1633 return;
1634 }
1635 if (s->missing_root_count > 0) {
1636 cbm_log_info("watcher.root_restored", "project", s->project_name, "path", s->root_path);
1637 s->missing_root_count = 0;
1638 s->first_missing_ms = 0;
1639 }
1640
1641 /* Initialize baseline on first poll */
1642 if (!s->baseline_done) {
1643 (void)init_baseline(ctx->w, s);
1644 return;
1645 }
1646
1647 /* Non-git projects are skipped unless the watch_non_git opt-in turned on
1648 * tree polling for them at baseline (#1948). */
1649 if (!s->is_git && !s->tree_poll) {
1650 return;
1651 }
1652

Callers 1

cbm_watcher_poll_onceFunction · 0.85

Calls 10

root_statusFunction · 0.85
cbm_now_msFunction · 0.85
prune_grace_sFunction · 0.85
prune_missing_projectFunction · 0.85
init_baselineFunction · 0.85
check_changesFunction · 0.85
publish_statusFunction · 0.85
commit_baselinesFunction · 0.85
itoa_bufFunction · 0.70

Tested by

no test coverage detected