Re: thread merge/split proposal
[notmuch-archives.git] / 42 / b68018a488c5ba3181d157f91be9fbb033ca28
1 Return-Path: <tomi.ollila@iki.fi>\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 arlo.cworth.org (Postfix) with ESMTP id DD1AD6DE026C\r
6  for <notmuch@notmuchmail.org>; Sun,  8 May 2016 09:47:43 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.594\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.594 tagged_above=-999 required=5 tests=[AWL=-0.058,\r
12   SPF_NEUTRAL=0.652] autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id 7CXR1POuGX9b for <notmuch@notmuchmail.org>;\r
16  Sun,  8 May 2016 09:47:35 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18  by arlo.cworth.org (Postfix) with ESMTP id 3604A6DE0022\r
19  for <notmuch@notmuchmail.org>; Sun,  8 May 2016 09:47:34 -0700 (PDT)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21  by guru.guru-group.fi (Postfix) with ESMTP id 1549F1000B3;\r
22  Sun,  8 May 2016 19:47:28 +0300 (EEST)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: Bijan Chokoufe Nejad <bijan@chokoufe.com>, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH] config: Expand ~ to $HOME\r
26 In-Reply-To: <1462722574-4176-1-git-send-email-bijan@chokoufe.com>\r
27 References: <1462722574-4176-1-git-send-email-bijan@chokoufe.com>\r
28 User-Agent: Notmuch/0.22+9~gb26b5ad (http://notmuchmail.org) Emacs/24.3.1\r
29  (x86_64-unknown-linux-gnu)\r
30 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
31  $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
32  !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
33 Date: Sun, 08 May 2016 19:47:27 +0300\r
34 Message-ID: <m2r3dc7azk.fsf@guru.guru-group.fi>\r
35 MIME-Version: 1.0\r
36 Content-Type: text/plain\r
37 X-BeenThere: notmuch@notmuchmail.org\r
38 X-Mailman-Version: 2.1.20\r
39 Precedence: list\r
40 List-Id: "Use and development of the notmuch mail system."\r
41  <notmuch.notmuchmail.org>\r
42 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
43  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
45 List-Post: <mailto:notmuch@notmuchmail.org>\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
47 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
48  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
49 X-List-Received-Date: Sun, 08 May 2016 16:47:44 -0000\r
50 \r
51 On Sun, May 08 2016, Bijan Chokoufe Nejad <bijan@chokoufe.com> wrote:\r
52 \r
53 > Very useful in case you want to keep your .notmuch-config synchronized across\r
54 > machines where you have different user names.\r
55 \r
56 Thank you for your interest in improving notmuch!\r
57 \r
58 There are a few things that needs to be sorted out for this feature to be\r
59 good:\r
60 \r
61 This implementation does not handle ~user/ prefix: i.e. home directory of\r
62 'user' (maybe this should not, but it should handle the case).\r
63 \r
64 Whether or not ~user is handled, it should check that slash (/) follows...\r
65 \r
66 IIRC there is some ready-made implementations of the above -- but if not,\r
67 one option is to check how (expand-file-name) works in emacs for reference.\r
68 \r
69 \r
70 Something more inline:\r
71 \r
72 \r
73 > ---\r
74 > Not sure this is completely plattform independent.\r
75 \r
76 The implementation looked like it is platform independent -- at least on\r
77 plattforms we care about...\r
78 \r
79 > I also don't know how to implement a unit test for this.\r
80 \r
81 I know... and I can do that if we get 1) decide that this feature will be\r
82 supported and 2) decide how this feature should work and 3) someone(tm)\r
83 does proper implementation ;)\r
84 \r
85 Tomi\r
86 \r
87 PS: still more to follow below.\r
88 \r
89 \r
90 > ---\r
91 >  notmuch-config.c | 11 ++++++++++-\r
92 >  1 file changed, 10 insertions(+), 1 deletion(-)\r
93 >\r
94 > diff --git a/notmuch-config.c b/notmuch-config.c\r
95 > index d252bb2..c9f26ef 100644\r
96 > --- a/notmuch-config.c\r
97 > +++ b/notmuch-config.c\r
98 > @@ -605,7 +605,16 @@ _config_set_list (notmuch_config_t *config,\r
99 >  const char *\r
100 >  notmuch_config_get_database_path (notmuch_config_t *config)\r
101 >  {\r
102 > -    return _config_get (config, &config->database_path, "database", "path");\r
103 > +    const char* path = _config_get (config, &config->database_path, "database", "path");\r
104 > +    if (path != NULL && path[0] == '~') {\r
105 > +        char *home_path = getenv("HOME");\r
106 > +        char *shortened_path = malloc( sizeof(char) * ( strlen (path) - 1 ) );\r
107 > +        strncpy(shortened_path, path + 2, strlen(path));\r
108 > +        return talloc_asprintf (NULL, "%s/%s", home_path, shortened_path);\r
109 \r
110 In the implementation above matching free() for malloc() is not done -- but\r
111 actually the malloc is unnecessary -- path + 2 could have been used there\r
112 (after one checked that path[1] is '/' (provided that ~/ were the only\r
113 thing we supported...))\r
114 \r
115 In strncpy() above length arg is strlen(path) but there is 1 byte less\r
116 allocated in shortened_path -- if src arg in the above strncpy() were\r
117 something else it could overwrite the allocated space by 2 bytes.\r
118 \r
119 \r
120 \r
121 > +    }\r
122 > +    else {\r
123 > +        return path;\r
124 > +    }\r
125 >  }\r
126 >  \r
127 >  void\r
128 > -- \r
129 > 1.9.1\r
130 >\r
131 > _______________________________________________\r
132 > notmuch mailing list\r
133 > notmuch@notmuchmail.org\r
134 > https://notmuchmail.org/mailman/listinfo/notmuch\r