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

Function ensure_parent_dir

src/cli/cli.c:3220–3239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3218}
3219
3220static int ensure_parent_dir(const char *path) {
3221 if (!path || !path[0]) {
3222 return CLI_ERR;
3223 }
3224 char dir[CLI_BUF_1K];
3225 int written = snprintf(dir, sizeof(dir), "%s", path);
3226 if (written < 0 || (size_t)written >= sizeof(dir)) {
3227 return CLI_ERR;
3228 }
3229 char *last_slash = strrchr(dir, '/');
3230 char *last_backslash = strrchr(dir, '\\');
3231 if (last_backslash && (!last_slash || last_backslash > last_slash)) {
3232 last_slash = last_backslash;
3233 }
3234 if (!last_slash || last_slash == dir) {
3235 return CLI_OK;
3236 }
3237 *last_slash = '\0';
3238 return mkdirp(dir, DIR_PERMS) == 0 ? CLI_OK : CLI_ERR;
3239}
3240
3241int cbm_upsert_instructions(const char *path, const char *content) {
3242 if (!path || !content) {

Calls 1

mkdirpFunction · 0.85

Tested by

no test coverage detected