From: Mark Walters <markwalters1009@gmail.com>
To: Peter Wang <novalazy@gmail.com>, notmuch@notmuchmail.org
Subject: Re: [PATCH 16/18] insert: add --create-folder option
Date: Sun, 18 Nov 2012 17:24:46 +0000 [thread overview]
Message-ID: <87lidyq0wx.fsf@qmul.ac.uk> (raw)
In-Reply-To: <1343223767-9812-16-git-send-email-novalazy@gmail.com>
Hi
On Wed, 25 Jul 2012, Peter Wang <novalazy@gmail.com> wrote:
> Support an option to create a new folder in the maildir.
> ---
> notmuch-insert.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 71 insertions(+), 0 deletions(-)
>
> diff --git a/notmuch-insert.c b/notmuch-insert.c
> index a69dfe6..380c520 100644
> --- a/notmuch-insert.c
> +++ b/notmuch-insert.c
> @@ -48,6 +48,70 @@ check_folder_name (const char *folder)
> }
> }
>
> +static int
> +mkdir_parents (void *ctx, const char *path, int mode)
> +{
> + struct stat st;
> + char *pathcopy;
> + char *start;
> + char *end;
> + int ret;
> +
> + /* First check the common case: directory already exists. */
> + if (stat (path, &st) == 0) {
> + return (S_ISDIR (st.st_mode)) ? 0 : -1;
> + }
> +
> + pathcopy = talloc_strdup (ctx, path);
> + ret = 0;
> +
> + for (start = pathcopy; *start != '\0'; start = end + 1) {
> + end = strchr (start + 1, '/');
> + if (!end) {
> + ret = mkdir (path, mode);
> + break;
> + }
> + *end = '\0';
> + ret = mkdir (pathcopy, mode);
> + if (ret != 0 && errno != EEXIST) {
> + break;
> + }
> + *end = '/';
> + }
I am a little confused by this: why is there a +1 in the start = end + 1
line and in the end = strchr line? I believe it doesn't matter but it
makes me wonder if I am missing something.
Best wishes
Mark
> +
> + talloc_free (pathcopy);
> +
> + return ret;
> +}
> +
> +static notmuch_bool_t
> +maildir_create (void *ctx, const char *dir)
> +{
> + const int mode = 0755;
> + char *subdir;
> + char *end;
> +
> + /* Create 'cur' directory, including parent directories. */
> + subdir = talloc_asprintf (ctx, "%s/cur", dir);
> + if (mkdir_parents (ctx, subdir, mode) != 0)
> + return FALSE;
> +
> + end = subdir + strlen (subdir);
> +
> + /* Create 'new' directory. */
> + strcpy (end - 3, "new");
> + if (mkdir (subdir, mode) != 0 && errno != EEXIST)
> + return FALSE;
> +
> + /* Create 'tmp' directory. */
> + strcpy (end - 3, "tmp");
> + if (mkdir (subdir, mode) != 0 && errno != EEXIST)
> + return FALSE;
> +
> + talloc_free (subdir);
> + return TRUE;
> +}
> +
> static notmuch_bool_t
> safe_gethostname (char *hostname, size_t hostname_size)
> {
> @@ -253,6 +317,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])
> const char **new_tags;
> size_t new_tags_length;
> const char *folder = NULL;
> + notmuch_bool_t create_folder = FALSE;
> tag_operation_t *tag_ops;
> int tag_ops_count = 0;
> char *maildir;
> @@ -262,6 +327,7 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])
>
> notmuch_opt_desc_t options[] = {
> { NOTMUCH_OPT_STRING, &folder, "folder", 0, 0 },
> + { NOTMUCH_OPT_BOOLEAN, &create_folder, "create-folder", 0, 0 },
> { NOTMUCH_OPT_END, 0, 0, 0, 0 }
> };
>
> @@ -328,6 +394,11 @@ notmuch_insert_command (void *ctx, int argc, char *argv[])
> return 1;
> }
> maildir = talloc_asprintf (ctx, "%s/%s", db_path, folder);
> + if (create_folder && ! maildir_create (ctx, maildir)) {
> + fprintf (stderr, "Error: creating maildir %s: %s\n",
> + maildir, strerror (errno));
> + return 1;
> + }
> } else {
> maildir = talloc_asprintf (ctx, "%s", db_path);
> }
> --
> 1.7.4.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
next prev parent reply other threads:[~2012-11-18 17:24 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-25 13:42 [PATCH 01/18] cli: add stub for insert command Peter Wang
2012-07-25 13:42 ` [PATCH 02/18] insert: open database Peter Wang
2012-07-25 13:42 ` [PATCH 03/18] insert: open Maildir tmp file Peter Wang
2012-11-18 15:47 ` Mark Walters
2012-07-25 13:42 ` [PATCH 04/18] insert: copy stdin to " Peter Wang
2012-11-26 16:21 ` Ali Polatel
2012-07-25 13:42 ` [PATCH 05/18] insert: move file from Maildir tmp to new Peter Wang
2012-11-18 17:33 ` Mark Walters
2012-11-19 12:26 ` Peter Wang
2012-11-19 13:49 ` Mark Walters
2012-07-25 13:42 ` [PATCH 06/18] insert: add new message to database Peter Wang
2012-11-18 17:00 ` Mark Walters
2012-07-25 13:42 ` [PATCH 07/18] insert: add --folder option Peter Wang
2012-07-25 13:42 ` [PATCH 08/18] insert: check folder name Peter Wang
2012-07-25 13:42 ` [PATCH 09/18] insert: apply default tags to new message Peter Wang
2012-07-25 13:42 ` [PATCH 10/18] insert: parse command-line tag operations Peter Wang
2012-11-18 17:05 ` Mark Walters
2012-07-25 13:42 ` [PATCH 11/18] insert: apply " Peter Wang
2012-07-25 13:42 ` [PATCH 12/18] insert: add copyright line from notmuch-deliver Peter Wang
2012-07-25 13:42 ` [PATCH 13/18] test: add tests for insert Peter Wang
2012-07-25 13:42 ` [PATCH 14/18] man: document 'insert' command Peter Wang
2012-11-18 17:13 ` Mark Walters
2012-07-25 13:42 ` [PATCH 15/18] man: reference notmuch-insert.1 Peter Wang
2012-07-25 13:42 ` [PATCH 16/18] insert: add --create-folder option Peter Wang
2012-11-18 17:24 ` Mark Walters [this message]
2012-07-25 13:42 ` [PATCH 17/18] man: document insert " Peter Wang
2012-07-25 13:42 ` [PATCH 18/18] test: test insert --create-folder Peter Wang
2012-07-25 17:11 ` [PATCH 01/18] cli: add stub for insert command Jameson Graef Rollins
2012-07-26 0:49 ` Peter Wang
2012-11-19 12:15 ` David Bremner
2012-11-18 17:35 ` Mark Walters
2012-11-19 12:34 ` Peter Wang
2012-11-19 13:52 ` Mark Walters
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lidyq0wx.fsf@qmul.ac.uk \
--to=markwalters1009@gmail.com \
--cc=notmuch@notmuchmail.org \
--cc=novalazy@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).