/* 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;
int output_is_a_tty;
enum verbosity verbosity;
bool debug;
bool full_scan;
const char **new_tags;
size_t new_tags_length;
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;
bool 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 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, sizeof(msg)-1));
interrupted = 1;
}
static _filename_list_t *
_filename_list_create (const void *ctx)
{
_filename_list_t *list;
list = talloc (ctx,