From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id A7939429E48 for ; Wed, 15 Feb 2012 14:10:30 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.54 X-Spam-Level: X-Spam-Status: No, score=-0.54 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_BL_SPAMCOP_NET=1.246, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_SORBS_WEB=0.614] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id w3ZrmvnjD5Zl for ; Wed, 15 Feb 2012 14:10:30 -0800 (PST) Received: from cliffclavin.cs.rpi.edu (cliffclavin.cs.rpi.edu [128.113.126.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id D6AAB429E43 for ; Wed, 15 Feb 2012 14:10:29 -0800 (PST) X-Hash: S|27febe0d6a4a25f7165855ffcf20f3e2c2e41321|d46bf90b1bccc1c6fd89498d004525ee X-Countries: Cameroon, United States X-SMTP-From: accepted [195.24.209.20] [195.24.209.20] (localhost) {Cameroon} DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=cs.rpi.edu; h=from :to:cc:subject:date:message-id:in-reply-to:references; s= default; i=glasse@cs.rpi.edu; t=1329343827; x=1329948627; l=4690; bh=1gAx2pb+B+LfzgRdy0uZzzlaHmY=; b=Ips66o/vU8UNdpRkj5ujg91 Gwf/71hDPAEs+KnYN4QPKP1xRk8UntxS5oosR3wHhmm/S3fKJqvL0hD+gJgw4lKx brsuk0E/NvhnpIN0ZCdYitEMm1aKsU8nBOBwoMPpqNisuuZNai+vlPo6AGIYT/Sc aA8T+1iEmW0Gm06JlrMQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=cs.rpi.edu; h=from:to:cc :subject:date:message-id:in-reply-to:references; q=dns; s= default; b=Z3UCn4n21CxtwkaHSSJcYLmhaxTp9y4K3Vp+ApBPabX34eEe3eRn6 x6krPyGTw/Pc8ShYI/z1WjDqcENBuczt3096jlbf5pR7RUnVXzvh8RUePmfJbxrw MxIBsB/fMrdZ/LsD2iBsQyk7QTa3jPMDguSlaiqEOoT2iOY5gKl+io= X-Spam-Info: -2.7; ALL_TRUSTED,AWL,BAYES_00 X-Spam-Scanned-By: cliffclavin.cs.rpi.edu using SpamAssassin 3.2.5 (hard limit 15) Authentication-Results: cliffclavin.cs.rpi.edu; DKIM=neutral (none) header.from=glasse@cs.rpi.edu; SPF=neutral (mfrom; Mechanism '?all' matched) smtp.mail=glasse@cs.rpi.edu X-Auth-Passed: cliffclavin.cs.rpi.edu:q1FM9tuK008835 Auth:glasse X-Virus-Scanned-By: cliffclavin.cs.rpi.edu Received: from localhost ([195.24.209.20]) (authenticated bits=0) by cliffclavin.cs.rpi.edu (8.14.3/8.14.3) with ESMTP id q1FM9tuK008835 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 15 Feb 2012 17:10:19 -0500 (EST) (envelope-from glasse@cs.rpi.edu) From: Ethan Glasser-Camp To: notmuch@notmuchmail.org Subject: [RFC PATCH 08/13] count_files and add_files shall be generic Date: Wed, 15 Feb 2012 17:02:01 -0500 Message-Id: <1329343326-16410-9-git-send-email-glasse@cs.rpi.edu> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu> References: <1329343326-16410-1-git-send-email-glasse@cs.rpi.edu> X-Scanned-By: MIMEDefang 2.67 on 128.113.126.25 Cc: Ethan Glasser-Camp X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Feb 2012 22:10:30 -0000 From: Ethan Glasser-Camp Rename current count_files and add_files to maildir_count_files and maildir_add_files. This allows the possibility, at least, of having other backends. Signed-off-by: Ethan Glasser-Camp --- notmuch-new.c | 62 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 50 insertions(+), 12 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index dbdfbb6..d30fba1 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -340,9 +340,9 @@ _add_message (add_files_state_t *state, notmuch_database_t *notmuch, * if fs_mtime isn't the current wall-clock time. */ static notmuch_status_t -add_files_recursive (notmuch_database_t *notmuch, - const char *path, - add_files_state_t *state) +maildir_add_files_recursive (notmuch_database_t *notmuch, + const char *path, + add_files_state_t *state) { DIR *dir = NULL; struct dirent *entry = NULL; @@ -449,7 +449,7 @@ add_files_recursive (notmuch_database_t *notmuch, } next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name); - status = add_files_recursive (notmuch, next, state); + status = maildir_add_files_recursive (notmuch, next, state); if (status && ret == NOTMUCH_STATUS_SUCCESS) ret = status; talloc_free (next); @@ -663,13 +663,34 @@ stop_progress_printing_timer (void) sigaction (SIGALRM, &action, NULL); } +static notmuch_status_t +maildir_add_files (notmuch_database_t *notmuch, + const char *path, + add_files_state_t *state); + +/* Dispatch function to call the correct mailstore_add_files + * function. */ +static notmuch_status_t +add_files (notmuch_database_t *notmuch, notmuch_config_t *config, + add_files_state_t *state) +{ + const char *path = notmuch_config_get_database_path (config); + if (strcmp (notmuch_config_get_database_type (config), "maildir") == 0) + return maildir_add_files (notmuch, path, state); + + /* Default case */ + fprintf (stderr, "Could not add files for mailstore %s: unknown mailstore\n", + notmuch_config_get_database_type (config)); + /* FIXME: "invalid argument" error code would be nice */ + return NOTMUCH_STATUS_FILE_ERROR; +} /* This is the top-level entry point for add_files. It does a couple * of error checks and then calls into the recursive function. */ static notmuch_status_t -add_files (notmuch_database_t *notmuch, - const char *path, - add_files_state_t *state) +maildir_add_files (notmuch_database_t *notmuch, + const char *path, + add_files_state_t *state) { notmuch_status_t status; struct stat st; @@ -685,11 +706,28 @@ add_files (notmuch_database_t *notmuch, return NOTMUCH_STATUS_FILE_ERROR; } - status = add_files_recursive (notmuch, path, state); + status = maildir_add_files_recursive (notmuch, path, state); return status; } +static void +maildir_count_files (const char *path, int *count); + +/* Dispatch function to call the correct mailstore_count_files + * function. N.B. This function may get refactored into add_files! */ +static void +count_files (unused (notmuch_database_t *notmuch), notmuch_config_t *config, int *count) +{ + if (strcmp (notmuch_config_get_database_type (config), "maildir") == 0) { + maildir_count_files (notmuch_config_get_database_path (config), count); + return; + } + + /* Eh, screw it, this function shouldn't even exist */ + *count = 0; +} + /* XXX: This should be merged with the add_files function since it * shares a lot of logic with it. */ /* Recursively count all regular files in path and all sub-directories @@ -697,7 +735,7 @@ add_files (notmuch_database_t *notmuch, * initialized to zero by the top-level caller before calling * count_files). */ static void -count_files (const char *path, int *count) +maildir_count_files (const char *path, int *count) { struct dirent *entry = NULL; char *next; @@ -746,7 +784,7 @@ count_files (const char *path, int *count) fflush (stdout); } } else if (S_ISDIR (st.st_mode)) { - count_files (next, count); + maildir_count_files (next, count); } free (next); @@ -905,7 +943,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) int count; count = 0; - count_files (db_path, &count); + count_files (notmuch, config, &count); if (interrupted) return 1; @@ -962,7 +1000,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) timer_is_active = TRUE; } - ret = add_files (notmuch, db_path, &add_files_state); + ret = add_files (notmuch, config, &add_files_state); gettimeofday (&tv_start, NULL); for (f = add_files_state.removed_files->head; f && !interrupted; f = f->next) { -- 1.7.5.4