* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program. If not, see http://www.gnu.org/licenses/ .
+ * along with this program. If not, see https://www.gnu.org/licenses/ .
*
* Author: Carl Worth <cworth@cworth.org>
*/
static const char toplevel_config_comment[] =
" .notmuch-config - Configuration file for the notmuch mail system\n"
"\n"
- " For more information about notmuch, see http://notmuchmail.org";
+ " For more information about notmuch, see https://notmuchmail.org";
static const char database_config_comment[] =
" Database configuration\n"
return name;
}
+static notmuch_bool_t
+get_config_from_file (notmuch_config_t *config, notmuch_bool_t create_new)
+{
+ #define BUF_SIZE 4096
+ char *config_str = NULL;
+ int config_len = 0;
+ int config_bufsize = BUF_SIZE;
+ size_t len;
+ GError *error = NULL;
+ notmuch_bool_t ret = FALSE;
+
+ FILE *fp = fopen(config->filename, "r");
+ if (fp == NULL) {
+ /* If create_new is true, then the caller is prepared for a
+ * default configuration file in the case of FILE NOT FOUND.
+ */
+ if (create_new) {
+ config->is_new = TRUE;
+ ret = TRUE;
+ goto out;
+ } else if (errno == ENOENT) {
+ fprintf (stderr, "Configuration file %s not found.\n"
+ "Try running 'notmuch setup' to create a configuration.\n",
+ config->filename);
+ goto out;
+ } else {
+ fprintf (stderr, "Error opening config file '%s': %s\n"
+ "Try running 'notmuch setup' to create a configuration.\n",
+ config->filename, strerror(errno));
+ goto out;
+ }
+ }
+
+ config_str = talloc_zero_array (config, char, config_bufsize);
+ if (config_str == NULL) {
+ fprintf (stderr, "Error reading '%s': Out of memory\n", config->filename);
+ goto out;
+ }
+
+ while ((len = fread (config_str + config_len, 1,
+ config_bufsize - config_len, fp)) > 0) {
+ config_len += len;
+ if (config_len == config_bufsize) {
+ config_bufsize += BUF_SIZE;
+ config_str = talloc_realloc (config, config_str, char, config_bufsize);
+ if (config_str == NULL) {
+ fprintf (stderr, "Error reading '%s': Failed to reallocate memory\n",
+ config->filename);
+ goto out;
+ }
+ }
+ }
+
+ if (ferror (fp)) {
+ fprintf (stderr, "Error reading '%s': I/O error\n", config->filename);
+ goto out;
+ }
+
+ if (g_key_file_load_from_data (config->key_file, config_str, config_len,
+ G_KEY_FILE_KEEP_COMMENTS, &error)) {
+ ret = TRUE;
+ goto out;
+ }
+
+ fprintf (stderr, "Error parsing config file '%s': %s\n",
+ config->filename, error->message);
+
+ g_error_free (error);
+
+out:
+ if (fp)
+ fclose(fp);
+
+ if (config_str)
+ talloc_free(config_str);
+
+ return ret;
+}
+
/* Open the named notmuch configuration file. If the filename is NULL,
* the value of the environment variable $NOTMUCH_CONFIG will be used.
* If $NOTMUCH_CONFIG is unset, the default configuration file
config->search_exclude_tags_length = 0;
config->crypto_gpg_path = NULL;
- if (! g_key_file_load_from_file (config->key_file,
- config->filename,
- G_KEY_FILE_KEEP_COMMENTS,
- &error))
- {
- if (error->domain == G_FILE_ERROR && error->code == G_FILE_ERROR_NOENT) {
- /* If create_new is true, then the caller is prepared for a
- * default configuration file in the case of FILE NOT
- * FOUND.
- */
- if (create_new) {
- g_error_free (error);
- config->is_new = TRUE;
- } else {
- fprintf (stderr, "Configuration file %s not found.\n"
- "Try running 'notmuch setup' to create a configuration.\n",
- config->filename);
- talloc_free (config);
- g_error_free (error);
- return NULL;
- }
- }
- else
- {
- fprintf (stderr, "Error reading configuration file %s: %s\n",
- config->filename, error->message);
- talloc_free (config);
- g_error_free (error);
- return NULL;
- }
+ if (! get_config_from_file (config, create_new)) {
+ talloc_free (config);
+ return NULL;
}
/* Whenever we know of configuration sections that don't appear in
printf("%sfield_processor=%s\n",
BUILT_WITH_PREFIX,
notmuch_built_with ("field_processor") ? "true" : "false");
+ printf("%sretry_lock=%s\n",
+ BUILT_WITH_PREFIX,
+ notmuch_built_with ("retry_lock") ? "true" : "false");
}
static int