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

Function cbm_ensure_path

src/cli/cli.c:5827–5871  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5825/* ── PATH management ──────────────────────────────────────────── */
5826
5827int cbm_ensure_path(const char *bin_dir, const char *rc_file, bool dry_run) {
5828 if (!bin_dir || !rc_file) {
5829 return CLI_ERR;
5830 }
5831
5832 /* fish uses a different syntax than POSIX shells: `export PATH="...:$PATH"`
5833 * is a syntax error in fish and breaks config.fish (#319). When the target
5834 * is a fish config, emit the fish-native `fish_add_path` (idempotent,
5835 * prepends only if absent) instead. */
5836 size_t rc_len = strlen(rc_file);
5837 bool is_fish = rc_len >= CBM_SZ_5 && strcmp(rc_file + rc_len - CBM_SZ_5, ".fish") == 0;
5838
5839 char line[CLI_BUF_1K];
5840 if (is_fish) {
5841 snprintf(line, sizeof(line), "fish_add_path %s", bin_dir);
5842 } else {
5843 snprintf(line, sizeof(line), "export PATH=\"%s:$PATH\"", bin_dir);
5844 }
5845
5846 /* Check if already present in rc file */
5847 FILE *f = fopen(rc_file, "r");
5848 if (f) {
5849 char buf[CLI_BUF_2K];
5850 while (fgets(buf, sizeof(buf), f)) {
5851 if (strstr(buf, line)) {
5852 (void)fclose(f);
5853 return CLI_TRUE; /* already present */
5854 }
5855 }
5856 (void)fclose(f);
5857 }
5858
5859 if (dry_run) {
5860 return 0;
5861 }
5862
5863 f = fopen(rc_file, "a");
5864 if (!f) {
5865 return CLI_ERR;
5866 }
5867
5868 (void)fprintf(f, "\n# Added by codebase-memory-mcp install\n%s\n", line);
5869 (void)fclose(f);
5870 return 0;
5871}
5872
5873#ifdef _WIN32
5874static 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