From cd11a80b9963fbc0f6183ea4383a28cf3d96fac2 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Wed, 11 Sep 2019 19:40:48 -0700 Subject: [PATCH] Convert query_pipe_attachment to use buffer pool Co-authored-by: Richard Russon --- muttlib.c | 26 +++++++++++++------------- recvattach.c | 29 +++++++++++++++-------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/muttlib.c b/muttlib.c index 5b67f4792..48154fea7 100644 --- a/muttlib.c +++ b/muttlib.c @@ -712,10 +712,10 @@ int mutt_check_overwrite(const char *attname, const char *path, struct Buffer *f { struct stat st; - mutt_buffer_strcpy (fname, path); - if (access (mutt_b2s (fname), F_OK) != 0) + mutt_buffer_strcpy(fname, path); + if (access(mutt_b2s(fname), F_OK) != 0) return 0; - if (stat (mutt_b2s (fname), &st) != 0) + if (stat(mutt_b2s(fname), &st) != 0) return -1; if (S_ISDIR(st.st_mode)) { @@ -729,7 +729,7 @@ int mutt_check_overwrite(const char *attname, const char *path, struct Buffer *f (_("File is a directory, save under it: (y)es, (n)o, (a)ll?"), _("yna"))) { case 3: /* all */ - mutt_str_replace (directory, mutt_b2s (fname)); + mutt_str_replace(directory, mutt_b2s(fname)); break; case 1: /* yes */ FREE(directory); @@ -747,22 +747,22 @@ int mutt_check_overwrite(const char *attname, const char *path, struct Buffer *f else if ((ans = mutt_yesorno(_("File is a directory, save under it?"), MUTT_YES)) != MUTT_YES) return (ans == MUTT_NO) ? 1 : -1; - struct Buffer *tmp = mutt_buffer_pool_get (); - mutt_buffer_strcpy (tmp, mutt_path_basename (NONULL (attname))); - if (mutt_get_field (_("File under directory: "), tmp->data, tmp->dsize, - MUTT_FILE | MUTT_CLEAR) != 0) + struct Buffer *tmp = mutt_buffer_pool_get(); + mutt_buffer_strcpy(tmp, mutt_path_basename(NONULL(attname))); + if (mutt_get_field(_("File under directory: "), tmp->data, tmp->dsize, + MUTT_FILE | MUTT_CLEAR) != 0) { - mutt_buffer_pool_release (&tmp); + mutt_buffer_pool_release(&tmp); return -1; } - mutt_buffer_fix_dptr (tmp); + mutt_buffer_fix_dptr(tmp); if (mutt_buffer_is_empty(tmp)) { - mutt_buffer_pool_release (&tmp); + mutt_buffer_pool_release(&tmp); return (-1); } - mutt_buffer_concat_path (fname, path, mutt_b2s (tmp)); - mutt_buffer_pool_release (&tmp); + mutt_buffer_concat_path(fname, path, mutt_b2s(tmp)); + mutt_buffer_pool_release(&tmp); } if ((*opt == MUTT_SAVE_NO_FLAGS) && (access(mutt_b2s(fname), F_OK) == 0)) diff --git a/recvattach.c b/recvattach.c index e1bf1758b..ff309be24 100644 --- a/recvattach.c +++ b/recvattach.c @@ -657,8 +657,8 @@ void mutt_save_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, FILE *fp_out = NULL; int saved_attachments = 0; - struct Buffer *buf = mutt_buffer_pool_get (); - struct Buffer *tfile = mutt_buffer_pool_get (); + struct Buffer *buf = mutt_buffer_pool_get(); + struct Buffer *tfile = mutt_buffer_pool_get(); for (int i = 0; !tag || (i < actx->idxlen); i++) { @@ -671,24 +671,25 @@ void mutt_save_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, { if (!C_AttachSplit) { - if (mutt_buffer_is_empty (buf)) + if (mutt_buffer_is_empty(buf)) { enum SaveAttach opt = MUTT_SAVE_NO_FLAGS; - mutt_buffer_strcpy (buf, mutt_path_basename (NONULL (top->filename))); + mutt_buffer_strcpy(buf, mutt_path_basename(NONULL(top->filename))); prepend_savedir(buf); - if (mutt_get_field (_("Save to file: "), buf->data, buf->dsize, MUTT_FILE | MUTT_CLEAR) != 0) + if (mutt_get_field(_("Save to file: "), buf->data, buf->dsize, + MUTT_FILE | MUTT_CLEAR) != 0) { goto cleanup; } - mutt_buffer_fix_dptr (buf); - if (mutt_buffer_is_empty (buf)) - goto cleanup; - mutt_buffer_expand_path (buf); - if (mutt_check_overwrite (top->filename, mutt_b2s (buf), tfile, &opt, NULL)) + mutt_buffer_fix_dptr(buf); + if (mutt_buffer_is_empty(buf)) + goto cleanup; + mutt_buffer_expand_path(buf); + if (mutt_check_overwrite(top->filename, mutt_b2s(buf), tfile, &opt, NULL)) goto cleanup; - rc = mutt_save_attachment (fp, top, mutt_b2s (tfile), opt, e); + rc = mutt_save_attachment(fp, top, mutt_b2s(tfile), opt, e); if ((rc == 0) && C_AttachSep && (fp_out = fopen(mutt_b2s(tfile), "a"))) { fprintf(fp_out, "%s", C_AttachSep); @@ -697,7 +698,7 @@ void mutt_save_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, } else { - rc = mutt_save_attachment (fp, top, mutt_b2s (tfile), MUTT_SAVE_APPEND, e); + rc = mutt_save_attachment(fp, top, mutt_b2s(tfile), MUTT_SAVE_APPEND, e); if ((rc == 0) && C_AttachSep && (fp_out = fopen(mutt_b2s(tfile), "a"))) { fprintf(fp_out, "%s", C_AttachSep); @@ -755,8 +756,8 @@ void mutt_save_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, } cleanup: - mutt_buffer_pool_release (&buf); - mutt_buffer_pool_release (&tfile); + mutt_buffer_pool_release(&buf); + mutt_buffer_pool_release(&tfile); } /** -- 2.40.0