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

Function cbm_workspace_grant_add

src/foundation/workspace.c:426–486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

424}
425
426bool cbm_workspace_grant_add(const char *cache_dir, const char *home_dir,
427 const char *canonical_path, bool approve_sensitive, char *err,
428 size_t err_sz) {
429 if (err && err_sz) {
430 err[0] = '\0';
431 }
432 if (!cache_dir || !cache_dir[0] || !canonical_path || !canonical_path[0]) {
433 if (err) {
434 snprintf(err, err_sz, "no path given");
435 }
436 return false;
437 }
438
439 cbm_ws_verdict_t verdict = cbm_workspace_classify_root(canonical_path, home_dir, cache_dir);
440 if (verdict != CBM_WS_ALLOW) {
441 if (!cbm_workspace_verdict_is_overridable(verdict)) {
442 if (err) {
443 snprintf(err, err_sz, "%s", cbm_workspace_verdict_reason(verdict));
444 }
445 return false;
446 }
447 if (!approve_sensitive) {
448 /* Refuse by default and name the flag, rather than asking a question
449 * whose answer we cannot authenticate. */
450 if (err) {
451 snprintf(err, err_sz, "%s; re-run with --approve-sensitive if that is intended",
452 cbm_workspace_verdict_reason(verdict));
453 }
454 return false;
455 }
456 }
457
458 /* Already present is success, not a duplicate error. */
459 ws_match_t existing = {canonical_path, false, false};
460 (void)ws_grant_walk(cache_dir, ws_match_visit, &existing);
461 if (existing.contained) {
462 return true;
463 }
464
465 char store[WS_LINE_MAX];
466 if (!cbm_workspace_grant_path(cache_dir, store, sizeof(store))) {
467 if (err) {
468 snprintf(err, err_sz, "cache path too long");
469 }
470 return false;
471 }
472 FILE *f = cbm_fopen(store, "a");
473 if (!f) {
474 if (err) {
475 snprintf(err, err_sz, "cannot write %s", store);
476 }
477 return false;
478 }
479 bool sensitive = verdict == CBM_WS_DENY_SENSITIVE;
480 (void)fprintf(f, "%s%s\n", sensitive ? "!" : "", canonical_path);
481 bool ok = fclose(f) == 0;
482 if (!ok && err) {
483 snprintf(err, err_sz, "cannot write %s", store);

Callers 1

main_run_allow_rootFunction · 0.85

Calls 6

ws_grant_walkFunction · 0.85
cbm_workspace_grant_pathFunction · 0.85
cbm_fopenFunction · 0.85

Tested by

no test coverage detected