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

Function delete_cached_project_db

src/watcher/watcher.c:1041–1082  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1039}
1040
1041static bool delete_cached_project_db(const char *project_name) {
1042 if (!cbm_validate_project_name(project_name)) {
1043 return false;
1044 }
1045
1046 const char *cache_dir = cbm_resolve_cache_dir();
1047 if (!cache_dir) {
1048 return false;
1049 }
1050
1051 size_t cache_length = strlen(cache_dir);
1052 size_t project_length = strlen(project_name);
1053 if (cache_length > SIZE_MAX - project_length - sizeof("/.db")) {
1054 return false;
1055 }
1056 size_t path_capacity = cache_length + project_length + sizeof("/.db");
1057 char *path = malloc(path_capacity);
1058 char *sidecar = malloc(path_capacity + sizeof("-wal"));
1059 if (!path || !sidecar) {
1060 free(path);
1061 free(sidecar);
1062 return false;
1063 }
1064 int written = snprintf(path, path_capacity, "%s/%s.db", cache_dir, project_name);
1065 bool formatted = written > 0 && (size_t)written < path_capacity;
1066 bool removed = formatted && watcher_unlink_cached_file(project_name, path, "database");
1067 /* If the main DB could not be removed, preserve WAL/SHM: together they
1068 * may be the only recoverable committed generation. */
1069 if (removed) {
1070 written = snprintf(sidecar, path_capacity + sizeof("-wal"), "%s-wal", path);
1071 removed = written > 0 && (size_t)written < path_capacity + sizeof("-wal") &&
1072 watcher_unlink_cached_file(project_name, sidecar, "wal");
1073 }
1074 if (removed) {
1075 written = snprintf(sidecar, path_capacity + sizeof("-wal"), "%s-shm", path);
1076 removed = written > 0 && (size_t)written < path_capacity + sizeof("-wal") &&
1077 watcher_unlink_cached_file(project_name, sidecar, "shm");
1078 }
1079 free(path);
1080 free(sidecar);
1081 return removed;
1082}
1083
1084/* Hash table foreach callback to free state entries */
1085static void free_state_entry(const char *key, void *val, void *ud) {

Callers 1

prune_missing_projectFunction · 0.85

Calls 3

cbm_resolve_cache_dirFunction · 0.85

Tested by

no test coverage detected