Re: [PATCH 1/2] Add Google Inc. to AUTHORS as a contributor.
[notmuch-archives.git] / 06 / 508ecb3bffd6c80c4357803f574869431b809d
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
9 X-Spam-Flag: NO\r
10 X-Spam-Score: -0.7\r
11 X-Spam-Level: \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
35         rGfA==\r
36 X-Gm-Message-State:\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
49 Message-Id:\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
58 Precedence: list\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
69 \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
72 this is neglible.\r
73 ---\r
74  notmuch-insert.c |   39 +++++++++++++++++++++++++++------------\r
75  1 files changed, 27 insertions(+), 12 deletions(-)\r
76 \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
82      return TRUE;\r
83  }\r
84  \r
85 +/*\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
88 + */\r
89 +static char *\r
90 +tempfilename (const void *ctx)\r
91 +{\r
92 +    char *filename;\r
93 +    char hostname[256];\r
94 +    struct timeval tv;\r
95 +    pid_t pid;\r
96 +\r
97 +    /* We follow the Dovecot file name generation algorithm. */\r
98 +    pid = getpid ();\r
99 +    safe_gethostname (hostname, sizeof (hostname));\r
100 +    gettimeofday (&tv, NULL);\r
101 +\r
102 +    filename = talloc_asprintf (ctx, "%ld.M%ldP%d.%s",\r
103 +                               tv.tv_sec, tv.tv_usec, pid, hostname);\r
104 +    if (! filename)\r
105 +       fprintf (stderr, "Error: %s\n", strerror (ENOMEM));\r
106 +\r
107 +    return filename;\r
108 +}\r
109 +\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
116  {\r
117 -    pid_t pid;\r
118 -    char hostname[256];\r
119 -    struct timeval tv;\r
120      char *filename;\r
121      int fd = -1;\r
122  \r
123 -    /* We follow the Dovecot file name generation algorithm. */\r
124 -    pid = getpid ();\r
125 -    safe_gethostname (hostname, sizeof (hostname));\r
126      do {\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
133 +       if (! filename)\r
134             return -1;\r
135 -       }\r
136  \r
137         *tmppath = talloc_asprintf (ctx, "%s/tmp/%s", dir, filename);\r
138         if (! *tmppath) {\r
139 -- \r
140 1.7.2.5\r
141 \r