/* notmuch - Not much of an email program, (just index and search)
*
* Copyright © 2009 Carl Worth
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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 https://www.gnu.org/licenses/ .
*
* Author: Carl Worth <cworth@cworth.org>
*/
#include "notmuch-client.h"
#include "tag-util.h"
#include <unistd.h>
typedef struct _filename_node {
char *filename;
time_t mtime;
struct _filename_node *next;
} _filename_node_t;
typedef struct _filename_list {
unsigned count;
_filename_node_t *head;
_filename_node_t **tail;
} _filename_list_t;
enum verbosity {
VERBOSITY_QUIET,
VERBOSITY_NORMAL,
VERBOSITY_VERBOSE,
};
typedef struct {
const char *db_path;
const char *mail_root;
notmuch_indexopts_t *indexopts;
int output_is_a_tty;
enum verbosity verbosity;
bool debug;
bool full_scan;
notmuch_config_values_t *new_tags;
const char **ignore_verbatim;
size_t ignore_verbatim_length;
regex_t *ignore_regex;
size_t ignore_regex_length;
int total_files;
int processed_files;
int added_messages, removed_messages, renamed_messages;
int vanished_files;
struct timeval tv_start;
_filename_list_t *removed_files;
_filename_list_t *removed_directories;
_filename_list_t *directory_mtimes;
notmuch_bool_t synchronize_flags;
} add_files_state_t;
static volatile sig_atomic_t do_print_progress = 0;
static void
handle_sigalrm (unused (int signal))
{
do_print_progress = 1;
}
static volatile sig_atomic_t interrupted;
static void
handle_sigint (unused (int sig))
{
static const char msg[] = "Stopping... \n";
/* This write is "opportunistic", so it's okay to ignore the
* result. It is not required for correctness, and if it does
* fail or produce a short write, we want to get out of the signal
* handler as quickly as possible, not retry it. */
IGNORE_RESULT (write (2, msg,