mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
cli: strip trailing "/" from the final maildir path in notmuch insert
Several subtle interconnected changes here: - If the folder name passed as argument is the empty string "" or slash "/", the final maildir path would end up having "//" in it. We should strip the final maildir path, not folder. - The folder variable should really be const char *, another reason not to modify it. - The maildir variable is only const to let us point it at db_path directly. To be able to strip the maildir variable, always allocate it. Default folder to the empty string "", and don't treat folder not being present on the command line as anything special. As a side effect, we also create the cur/new/tmp in the top level directory if they're not there and --create-folder is given.
This commit is contained in:
parent
9d48ee2eaa
commit
d57da17fcd
1 changed files with 15 additions and 17 deletions
|
@ -452,12 +452,12 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
size_t new_tags_length;
|
||||
tag_op_list_t *tag_ops;
|
||||
char *query_string = NULL;
|
||||
char *folder = NULL;
|
||||
const char *folder = "";
|
||||
notmuch_bool_t create_folder = FALSE;
|
||||
notmuch_bool_t keep = FALSE;
|
||||
notmuch_bool_t no_hooks = FALSE;
|
||||
notmuch_bool_t synchronize_flags;
|
||||
const char *maildir;
|
||||
char *maildir;
|
||||
char *newpath;
|
||||
int opt_index;
|
||||
unsigned int i;
|
||||
|
@ -509,22 +509,20 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (folder == NULL) {
|
||||
maildir = db_path;
|
||||
} else {
|
||||
strip_trailing (folder, '/');
|
||||
if (! is_valid_folder_name (folder)) {
|
||||
fprintf (stderr, "Error: invalid folder name: '%s'\n", folder);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
maildir = talloc_asprintf (config, "%s/%s", db_path, folder);
|
||||
if (! maildir) {
|
||||
fprintf (stderr, "Out of memory\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
strip_trailing (maildir, '/');
|
||||
if (create_folder && ! maildir_create_folder (config, maildir))
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* Set up our handler for SIGINT. We do not set SA_RESTART so that copying
|
||||
* from standard input may be interrupted. */
|
||||
|
|
Loading…
Reference in a new issue