1 Return-Path: <jani@nikula.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id DB3D2429E36
\r
6 for <notmuch@notmuchmail.org>; Mon, 22 Sep 2014 02:55:14 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
8 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"
\r
12 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
13 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id uEJWtHJi3Udy for <notmuch@notmuchmail.org>;
\r
17 Mon, 22 Sep 2014 02:55:10 -0700 (PDT)
\r
18 Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com
\r
19 [209.85.212.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 518F4431FBC
\r
22 for <notmuch@notmuchmail.org>; Mon, 22 Sep 2014 02:54:58 -0700 (PDT)
\r
23 Received: by mail-wi0-f173.google.com with SMTP id r20so2554607wiv.12
\r
24 for <notmuch@notmuchmail.org>; Mon, 22 Sep 2014 02:54:57 -0700 (PDT)
\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
26 d=1e100.net; s=20130820;
\r
27 h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
\r
28 :references:in-reply-to:references;
\r
29 bh=PP97ENfqgEyJSXqIRz7IAcgX8LNKWfS+l2CzJgGJNQI=;
\r
30 b=D8h6soj/XK8J1rvHgAT7p22/CPm4Zwr5rU0BLB6Z2MW8CkQolYN7rKiyUtX291JNo1
\r
31 dvFl4sXbBLZtzXlKqdSbUXreDf+ysf6H7JAmcsLMgKYCTNngURSfNMvr/yJAc8Gir7/E
\r
32 tLHBXxeuaWgfDeRxkmV7R/CP1GtSVDRNYK4j2uPmWvtW2amt22j6QOIv9NwbPCLqz6lI
\r
33 tYW9fk/JXaXGQl/e7XN0k7qjU7GmizqORajAGCglmhL4AFEFftSJTQ8Q4bPt5b6XWz2K
\r
34 /4BiRJ49TBEtrmtplOP2KF+GEI/eOWscxk8wRZZeXL3KC1l0ikNWzdBs6OoV8ouwK+ya
\r
37 ALoCoQn+pKp9IezDt6vr2QrdOqdE2jTfvvpa4ryJDfQyGdi1gS2izpbKa3kgecFMFbS0VgO738uj
\r
38 X-Received: by 10.194.24.101 with SMTP id t5mr19092602wjf.76.1411379697162;
\r
39 Mon, 22 Sep 2014 02:54:57 -0700 (PDT)
\r
40 Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3])
\r
41 by mx.google.com with ESMTPSA id s7sm11686495wjo.48.2014.09.22.02.54.56
\r
42 for <multiple recipients>
\r
43 (version=TLSv1.1 cipher=RC4-SHA bits=128/128);
\r
44 Mon, 22 Sep 2014 02:54:56 -0700 (PDT)
\r
45 From: Jani Nikula <jani@nikula.org>
\r
46 To: notmuch@notmuchmail.org
\r
47 Subject: [PATCH 07/11] cli/insert: abstract temporary filename generation
\r
48 Date: Mon, 22 Sep 2014 11:54:58 +0200
\r
50 <550178f85df340b38eb82094a5f823c9673d83dc.1411379395.git.jani@nikula.org>
\r
51 X-Mailer: git-send-email 1.7.2.5
\r
52 In-Reply-To: <cover.1411379395.git.jani@nikula.org>
\r
53 References: <cover.1411379395.git.jani@nikula.org>
\r
54 In-Reply-To: <cover.1411379395.git.jani@nikula.org>
\r
55 References: <cover.1411379395.git.jani@nikula.org>
\r
56 X-BeenThere: notmuch@notmuchmail.org
\r
57 X-Mailman-Version: 2.1.13
\r
59 List-Id: "Use and development of the notmuch mail system."
\r
60 <notmuch.notmuchmail.org>
\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
64 List-Post: <mailto:notmuch@notmuchmail.org>
\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
67 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
68 X-List-Received-Date: Mon, 22 Sep 2014 09:55:15 -0000
\r
70 This will clean up the usage. There's the slight functional change of
\r
71 potentially ending up doing extra gethostname and getpid calls, but
\r
74 notmuch-insert.c | 39 +++++++++++++++++++++++++++------------
\r
75 1 files changed, 27 insertions(+), 12 deletions(-)
\r
77 diff --git a/notmuch-insert.c b/notmuch-insert.c
\r
78 index cdeeb41..a1d564c 100644
\r
79 --- a/notmuch-insert.c
\r
80 +++ b/notmuch-insert.c
\r
81 @@ -179,6 +179,31 @@ maildir_create_folder (const void *ctx, const char *maildir)
\r
86 + * Generate a temporary file basename, no path, do not create an
\r
87 + * actual file. Return the basename, or NULL on errors.
\r
90 +tempfilename (const void *ctx)
\r
93 + char hostname[256];
\r
94 + struct timeval tv;
\r
97 + /* We follow the Dovecot file name generation algorithm. */
\r
99 + safe_gethostname (hostname, sizeof (hostname));
\r
100 + gettimeofday (&tv, NULL);
\r
102 + filename = talloc_asprintf (ctx, "%ld.M%ldP%d.%s",
\r
103 + tv.tv_sec, tv.tv_usec, pid, hostname);
\r
105 + fprintf (stderr, "Error: %s\n", strerror (ENOMEM));
\r
110 /* Open a unique file in the 'tmp' sub-directory of dir.
\r
111 * Returns the file descriptor on success, or -1 on failure.
\r
112 * On success, file paths for the message in the 'tmp' and 'new'
\r
113 @@ -188,23 +213,13 @@ static int
\r
114 maildir_open_tmp_file (void *ctx, const char *dir,
\r
115 char **tmppath, char **newpath, char **newdir)
\r
118 - char hostname[256];
\r
119 - struct timeval tv;
\r
123 - /* We follow the Dovecot file name generation algorithm. */
\r
125 - safe_gethostname (hostname, sizeof (hostname));
\r
127 - gettimeofday (&tv, NULL);
\r
128 - filename = talloc_asprintf (ctx, "%ld.M%ldP%d.%s",
\r
129 - tv.tv_sec, tv.tv_usec, pid, hostname);
\r
130 - if (! filename) {
\r
131 - fprintf (stderr, "Out of memory\n");
\r
132 + filename = tempfilename (ctx);
\r
137 *tmppath = talloc_asprintf (ctx, "%s/tmp/%s", dir, filename);
\r