From 7e217b739ea55f12b84c55f238b37a730b759a3e Mon Sep 17 00:00:00 2001 From: Bijan Chokoufe Nejad Date: Mon, 9 May 2016 23:57:24 +0200 Subject: [PATCH] Re: [PATCH] config: Expand ~ to $HOME --- de/4e91d8640d0f3a6f33850b8ce47ec361e84519 | 218 ++++++++++++++++++++++ 1 file changed, 218 insertions(+) create mode 100644 de/4e91d8640d0f3a6f33850b8ce47ec361e84519 diff --git a/de/4e91d8640d0f3a6f33850b8ce47ec361e84519 b/de/4e91d8640d0f3a6f33850b8ce47ec361e84519 new file mode 100644 index 000000000..86bce0d68 --- /dev/null +++ b/de/4e91d8640d0f3a6f33850b8ce47ec361e84519 @@ -0,0 +1,218 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id AD9906DE0173 + for ; Mon, 9 May 2016 14:57:39 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: -0.82 +X-Spam-Level: +X-Spam-Status: No, score=-0.82 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, + RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id HgjtoxGPjqgU for ; + Mon, 9 May 2016 14:57:30 -0700 (PDT) +Received: from mail-wm0-f44.google.com (mail-wm0-f44.google.com + [74.125.82.44]) by arlo.cworth.org (Postfix) with ESMTPS id D2B846DE00DB for + ; Mon, 9 May 2016 14:57:29 -0700 (PDT) +Received: by mail-wm0-f44.google.com with SMTP id e201so154658009wme.0 + for ; Mon, 09 May 2016 14:57:29 -0700 (PDT) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; + h=date:from:to:cc:subject:message-id:references:mime-version + :content-disposition:in-reply-to:user-agent; + bh=rL/zsVsC0UgazDnXZ/73RVtYwEuNWltJGlZPul6vkPQ=; + b=mRRyC5O6gW2gZ9IeOFCPVlbS4J2qSDff2z08aGVz8g8BabjnWMfp9p+s7shk9KjiPJ + /0WNwfvaoqXyBfBflV+tkzwY+6OelK0T+VMU5wRKmgxaZcCNOMWj09YEjLrtRJoGTpqY + X45nMAqMu7coXGJkoLVv6ZPCK7OQqck0LMW9faaT1zasaYIvelhSdbL/EjNaHBbMVicO + fByxFXw8lUQrreLyBmfv/VIze3qCEi1YJA2GS6tFxM6Si7HGNZafpXUiyjwdJGPLybMK + bQHLUtlH2s7ivuGz2ZfQ95jfJyKf/zgFhllsZm7p0Kr+/D6/Hno2zIoaMGZjzejH79VO + Ii/A== +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:date:from:to:cc:subject:message-id:references + :mime-version:content-disposition:in-reply-to:user-agent; + bh=rL/zsVsC0UgazDnXZ/73RVtYwEuNWltJGlZPul6vkPQ=; + b=aJ1V6za7SrkYTpANwT4s0CoO92wyyxhQ3iz4gRkkNd60UwDA6h+k412xyZbWzQi4hI + R8ngtKZKrJv9He55tELw/t1fqQ+W3nCdDm6phPtkg9mL9FJ4Zxm/uO+byRODbbwj6U3G + xIuiOArDqo0miZZBmlg9akYsu0OE28OLzsNpzjAMcHBmQhePJdMFfrnjVJPbmosxexXI + /gIw0+GIYePTfIuAon53nBgNaLm9d+XyThgEt+Zy20Wb9ir7wJHs7h8oQQmtCgbJB5ZH + CFflFdc78lh+cerEvssBLY9DhvJ6yiHGau/sqplddkTI2CXpRxv+ESJa1wEPVGEioLzT + HBcw== +X-Gm-Message-State: + AOPr4FXw9CAxPkKDq6/zK9lN4blUG8YEcZV9cggPLQT37EWvhPe/Y9XppEIemuRZnjpzlQ== +X-Received: by 10.194.248.135 with SMTP id ym7mr35496223wjc.174.1462831048115; + Mon, 09 May 2016 14:57:28 -0700 (PDT) +Received: from localhost (ip5f5be327.dynamic.kabel-deutschland.de. + [95.91.227.39]) + by smtp.gmail.com with ESMTPSA id z125sm16796108wmg.24.2016.05.09.14.57.26 + (version=TLS1_2 cipher=AES128-SHA bits=128/128); + Mon, 09 May 2016 14:57:26 -0700 (PDT) +Date: Mon, 9 May 2016 23:57:24 +0200 +From: Bijan Chokoufe Nejad +To: Tomi Ollila +Cc: notmuch@notmuchmail.org +Subject: Re: [PATCH] config: Expand ~ to $HOME +Message-ID: <20160509215724.GA3634@600B5B> +References: <1462722574-4176-1-git-send-email-bijan@chokoufe.com> + + + +MIME-Version: 1.0 +Content-Type: multipart/mixed; boundary="ZPt4rx8FFjLCG7dd" +Content-Disposition: inline +In-Reply-To: +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Mailman-Approved-At: Mon, 09 May 2016 21:23:46 -0700 +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +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: Mon, 09 May 2016 21:57:39 -0000 + + +--ZPt4rx8FFjLCG7dd +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline + +On 16-05-09, Tomi Ollila wrote: +> On Sun, May 08 2016, Bijan Chokoufe wrote: +> +> > Hi Tomi, +> > +> > Thanks for your detailled review. Please see questions below. +> > +> > Cheers, +> > Bijan +> > +> > Tomi Ollila schrieb am So., 8. Mai 2016 um 18:47 Uhr: +> > +> >> On Sun, May 08 2016, Bijan Chokoufe Nejad wrote: +> >> +> >> > Very useful in case you want to keep your .notmuch-config synchronized +> >> across +> >> > machines where you have different user names. +> >> +> >> Thank you for your interest in improving notmuch! +> >> +> >> There are a few things that needs to be sorted out for this feature to be +> >> good: +> >> +> >> This implementation does not handle ~user/ prefix: i.e. home directory of +> >> 'user' (maybe this should not, but it should handle the case). +> > +> > I don't get it. Is '~user" an alternative to '~'? +> +> ~user is ~ in case you're 'user' -- except that now that I think of it +> ~user could read home directory from /etc/passwd and not using $HOME. +> If you're 'eve', then ~alice should definitely be different than ~ + +OK I see. I never used ~user instead of ~ and don't see any advantage in using +~user but good to know it's there. + +> +> > +> >> Whether or not ~user is handled, it should check that slash (/) follows... +> >> +> >> +> > So I guess you aim at the case where someone sets `path=~`? On the other +> > hand why is this checking not necessary in the "normal" case where no +> > expanding of `~` is done? Or is it maybe already handled in +> > `lib/database.cc`. Just to be clear I tested that it works currently with +> > `path=~/.mail`. +> +> your code checked that path[0] == '~', but nothing else, e.g. +> +> ~123randomstuff/... would expand as /home/user23randomstuff/... +> +> ... and you have good point path being set as single '~' ! +> +> >> IIRC there is some ready-made implementations of the above -- but if not, +> >> one option is to check how (expand-file-name) works in emacs for reference. +> >> +> >> +> > Well there is wordexp (http://linux.die.net/man/3/wordexp) but I wasn't +> > sure if I should use it. The getenv just seemed simpler but maybe it is +> > necessary. +> +> For the time being we could simply do checking that path[0] == '~' and +> path[1] == '/' and then do expansion based on getenv ("HOME") -- and +> comment that ~any_user is just not supported there. + +alright, done. I am still a bit confused by the way you do pull request here. +I am attaching the rebased commit as git patch. Is this correct or should I use +git send-email again? How do you keep track of lengthy PRs with this workflow? + +Cheers, +Bijan + +> +> From testing point of view doing one positive test which ensures that when +> HOME is a string pointing to valid directory (and does not end with +> trailing slash as it usually is) and path in configuration starts with '~/' +> (and does not have multiple slashes following) works as expected... +> +> (as a special case, from softare functionality point I don't see problem +> setting path=~/ but from usability point that might not be the best -- but +> some users may have peculiar preferences... ;D) +> +> Tomi + +--ZPt4rx8FFjLCG7dd +Content-Type: text/x-diff; charset=us-ascii +Content-Disposition: attachment; + filename="v2-0001-config-Expand-to-HOME.patch" + +>From ca6a86c6456d7fce2f18da8ec92d6d7ff14dc5f8 Mon Sep 17 00:00:00 2001 +From: Bijan Chokoufe Nejad +Date: Sun, 8 May 2016 15:47:50 +0200 +Subject: [PATCH v2] config: Expand ~ to $HOME + +Very useful in case you want to keep your .notmuch-config synchronized across +machines where you have different user names. + +--- +Check for '~/' instead of checking for '~' and fix memory issue. + +Unit test is still pending +--- + notmuch-config.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/notmuch-config.c b/notmuch-config.c +index d252bb2..e97d5b0 100644 +--- a/notmuch-config.c ++++ b/notmuch-config.c +@@ -605,7 +605,15 @@ _config_set_list (notmuch_config_t *config, + const char * + notmuch_config_get_database_path (notmuch_config_t *config) + { +- return _config_get (config, &config->database_path, "database", "path"); ++ const char* path = _config_get (config, &config->database_path, "database", "path"); ++ /* '~user/some/path' is not supported but only '~/some/path' */ ++ if (path != NULL && path[0] == '~' && path[1] == '/') { ++ char *home_path = getenv("HOME"); ++ return talloc_asprintf (NULL, "%s/%s", home_path, path + 2); ++ } ++ else { ++ return path; ++ } + } + + void +-- +1.9.1 + + +--ZPt4rx8FFjLCG7dd-- -- 2.26.2