From e2901a5506b701f7a64173feedf1d260dcfb2a96 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sun, 11 Sep 2022 10:01:05 +0200 Subject: [PATCH] Let rclgrep create its own config under $HOME/.config/rclgrep, because using the indexer config does not make much sense and presents issues (with logging mostly) --- src/rclgrep/rclgrep.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/rclgrep/rclgrep.cpp b/src/rclgrep/rclgrep.cpp index 87901370..2c7c6487 100644 --- a/src/rclgrep/rclgrep.cpp +++ b/src/rclgrep/rclgrep.cpp @@ -337,6 +337,38 @@ bool processpaths(RclConfig *config, const std::vector &_paths, return true; } +std::string make_config() +{ + std::string confdir; + const char *cp = nullptr; + cp = getenv("XDG_CONFIG_HOME"); + if (nullptr != cp) { + confdir = cp; + } else { + confdir = path_cat(path_home(), ".config"); + } + confdir = path_cat(confdir, "rclgrep"); + if (!path_makepath(confdir, 0755)) { + std::cerr << "Could not create configuration directory " << confdir << " : "; + perror(""); + exit(1); + } + std::string mainconf = path_cat(confdir, "recoll.conf"); + if (!path_exists(mainconf)) { + FILE *fp = fopen(mainconf.c_str(), "w"); + if (nullptr == fp) { + std::cerr << "Could not create configuration file " << mainconf << " : "; + perror(""); + exit(1); + } + fprintf(fp, "# rclgrep default configuration. Will only be created by the program if it\n"); + fprintf(fp, "# does not exist, you can add your own customisations in here\n"); + fprintf(fp, "helperlogfilename = /dev/null\n"); + fprintf(fp, "loglevel = 1\n"); + fclose(fp); + } + return confdir; +} std::string thisprog; @@ -435,6 +467,9 @@ int main(int argc, char *argv[]) op_flags |= OPT_H; } + if (a_config.empty()) { + a_config = make_config(); + } string reason; int flags = 0; config = recollinit(flags, nullptr, nullptr, reason, &a_config);