From 6fdec13469d0627db16bd0fd795fb998aa857af9 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Tue, 25 Mar 2014 19:07:50 +0200 Subject: [PATCH] [PATCH 2/2] cli: abstract dump file open from the dump command --- b0/dafc334f92ab20a0d4c79d0426dfcaa81b1f02 | 151 ++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 b0/dafc334f92ab20a0d4c79d0426dfcaa81b1f02 diff --git a/b0/dafc334f92ab20a0d4c79d0426dfcaa81b1f02 b/b0/dafc334f92ab20a0d4c79d0426dfcaa81b1f02 new file mode 100644 index 000000000..f51216ffa --- /dev/null +++ b/b0/dafc334f92ab20a0d4c79d0426dfcaa81b1f02 @@ -0,0 +1,151 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 2CDF6431FBF + for ; Tue, 25 Mar 2014 10:08:03 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 RU+4LbszokoC for ; + Tue, 25 Mar 2014 10:07:59 -0700 (PDT) +Received: from mail-ee0-f52.google.com (mail-ee0-f52.google.com + [74.125.83.52]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + 5BED8431FC0 for ; Tue, 25 Mar 2014 10:07:59 -0700 + (PDT) +Received: by mail-ee0-f52.google.com with SMTP id e49so699698eek.11 + for ; Tue, 25 Mar 2014 10:07:58 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references:in-reply-to:references; + bh=eUoxc5Cau1BOQncxLPyJmpBSprrtgIScYhtrM9R6Sm0=; + b=RHi3ji1bpszx3hTa2LG9I2oTTM5XjFqfs2EDVQ0iKuY3Jy1OWYtr2er1RCidNYor/j + TqnXnJhRpZfyuRwBoVTeD/vg34fe8CL+hnhxouwDXxw6woOmpl0vvu0kSMTBR7Zn10sK + /kHi2Jd/S+MBWTm666OTJ9ueeaBv9WByYxUHvq8GseU82Ar3fB2HE+RgJ7bbWIwLi7bj + cMGbL26CWVruTzTrg5GFCiCizmbAIxA471w38+Xt+AUbX8nItXq8GNB7N16bQRgNkOOZ + UW1mvBQxkPTn9KrxaQVoSZ2FPNAEFLQB13N2Hh0zIJ2WysTmVBznA4ucUcKqJQD2cLsC + RvtA== +X-Gm-Message-State: + ALoCoQmbBYXmakBWT57yoJqWXXGI0viTAb2tKrly7rz49KxF7evSigtjkaOhtQkde4uPd9+bvzVI +X-Received: by 10.14.39.65 with SMTP id c41mr1262236eeb.97.1395767277975; + Tue, 25 Mar 2014 10:07:57 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi. + [88.195.111.91]) + by mx.google.com with ESMTPSA id y7sm22946700eev.5.2014.03.25.10.07.56 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Tue, 25 Mar 2014 10:07:57 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH 2/2] cli: abstract dump file open from the dump command +Date: Tue, 25 Mar 2014 19:07:50 +0200 +Message-Id: + <92929cc512b9e9cd5ccb7d4e537671ce84de514f.1395767165.git.jani@nikula.org> +X-Mailer: git-send-email 1.9.0 +In-Reply-To: +References: +In-Reply-To: +References: +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: Tue, 25 Mar 2014 17:08:03 -0000 + +No functional changes, except for slight improvement in error +handling. +--- + notmuch-dump.c | 43 ++++++++++++++++++++++++++++--------------- + 1 file changed, 28 insertions(+), 15 deletions(-) + +diff --git a/notmuch-dump.c b/notmuch-dump.c +index 179e2e97bf61..88bef3f77e82 100644 +--- a/notmuch-dump.c ++++ b/notmuch-dump.c +@@ -115,11 +115,37 @@ database_dump_file (notmuch_database_t *notmuch, FILE *output, + return EXIT_SUCCESS; + } + ++/* Dump database into output_file_name if it's non-NULL, stdout ++ * otherwise. ++ */ ++static int ++database_dump (notmuch_database_t *notmuch, const char *output_file_name, ++ const char *query_str, int output_format) ++{ ++ FILE *output = stdout; ++ int ret; ++ ++ if (output_file_name) { ++ output = fopen (output_file_name, "w"); ++ if (output == NULL) { ++ fprintf (stderr, "Error opening %s for writing: %s\n", ++ output_file_name, strerror (errno)); ++ return EXIT_FAILURE; ++ } ++ } ++ ++ ret = database_dump_file (notmuch, output, query_str, output_format); ++ ++ if (output != stdout) ++ fclose (output); ++ ++ return ret; ++} ++ + int + notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]) + { + notmuch_database_t *notmuch; +- FILE *output = stdout; + const char *query_str = NULL; + int ret; + +@@ -145,16 +171,6 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]) + if (opt_index < 0) + return EXIT_FAILURE; + +- if (output_file_name) { +- output = fopen (output_file_name, "w"); +- if (output == NULL) { +- fprintf (stderr, "Error opening %s for writing: %s\n", +- output_file_name, strerror (errno)); +- return EXIT_FAILURE; +- } +- } +- +- + if (opt_index < argc) { + query_str = query_string_from_args (notmuch, argc - opt_index, argv + opt_index); + if (query_str == NULL) { +@@ -163,10 +179,7 @@ notmuch_dump_command (notmuch_config_t *config, int argc, char *argv[]) + } + } + +- ret = database_dump_file (notmuch, output, query_str, output_format); +- +- if (output != stdout) +- fclose (output); ++ ret = database_dump (notmuch, output_file_name, query_str, output_format); + + notmuch_database_destroy (notmuch); + +-- +1.9.0 + -- 2.26.2