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

Function cbm_ensure_path

src/cli/cli.c:5806–5850  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5804/* ── PATH management ──────────────────────────────────────────── */
5805
5806int cbm_ensure_path(const char *bin_dir, const char *rc_file, bool dry_run) {
5807 if (!bin_dir || !rc_file) {
5808 return CLI_ERR;
5809 }
5810
5811 /* fish uses a different syntax than POSIX shells: `export PATH="...:$PATH"`
5812 * is a syntax error in fish and breaks config.fish (#319). When the target
5813 * is a fish config, emit the fish-native `fish_add_path` (idempotent,
5814 * prepends only if absent) instead. */
5815 size_t rc_len = strlen(rc_file);
5816 bool is_fish = rc_len >= CBM_SZ_5 && strcmp(rc_file + rc_len - CBM_SZ_5, ".fish") == 0;
5817
5818 char line[CLI_BUF_1K];
5819 if (is_fish) {
5820 snprintf(line, sizeof(line), "fish_add_path %s", bin_dir);
5821 } else {
5822 snprintf(line, sizeof(line), "export PATH=\"%s:$PATH\"", bin_dir);
5823 }
5824
5825 /* Check if already present in rc file */
5826 FILE *f = fopen(rc_file, "r");
5827 if (f) {
5828 char buf[CLI_BUF_2K];
5829 while (fgets(buf, sizeof(buf), f)) {
5830 if (strstr(buf, line)) {
5831 (void)fclose(f);
5832 return CLI_TRUE; /* already present */
5833 }
5834 }
5835 (void)fclose(f);
5836 }
5837
5838 if (dry_run) {
5839 return 0;
5840 }
5841
5842 f = fopen(rc_file, "a");
5843 if (!f) {
5844 return CLI_ERR;
5845 }
5846
5847 (void)fprintf(f, "\n# Added by codebase-memory-mcp install\n%s\n", line);
5848 (void)fclose(f);
5849 return 0;
5850}
5851
5852#ifdef _WIN32
5853static wchar_t *cli_windows_utf8_to_wide(const char *value) {

Callers 2

cli_install_activateFunction · 0.85
test_cli.cFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected