From 4a02618b4b2a587cf36b7ef79ba51144f815b3a3 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Tue, 16 Apr 2019 12:23:42 -0700 Subject: [PATCH] Change struct Mailbox->realpath to be const char * struct Mailbox->path is a fixed array (which will be converted to a struct Buffer in the next commit). This is needed to call mutt_expand_path(). However, struct Mailbox->realpath has no such need, and so it is a bit wasteful (not to mention not big enough) to store as such. Co-authored-by: Richard Russon --- compress.c | 2 +- imap/imap.c | 2 +- mailbox.c | 1 + mailbox.h | 3 +-- mx.c | 13 ++++++++++--- pop/pop.c | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/compress.c b/compress.c index 65c31db49..4b3fb0865 100644 --- a/compress.c +++ b/compress.c @@ -140,7 +140,7 @@ static int setup_paths(struct Mailbox *m) char tmp[PATH_MAX]; /* Setup the right paths */ - mutt_str_strfcpy(m->realpath, m->path, sizeof(m->realpath)); + mutt_str_replace(&m->realpath, m->path); /* We will uncompress to /tmp */ mutt_mktemp(tmp, sizeof(tmp)); diff --git a/imap/imap.c b/imap/imap.c index 60c3b3e94..e33314020 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -1883,7 +1883,7 @@ int imap_ac_add(struct Account *a, struct Mailbox *m) char buf[1024]; imap_qualify_path(buf, sizeof(buf), &adata->conn_account, mdata->name); mutt_str_strfcpy(m->path, buf, sizeof(m->path)); - mutt_str_strfcpy(m->realpath, m->path, sizeof(m->realpath)); + mutt_str_replace(&m->realpath, m->path); m->mdata = mdata; m->free_mdata = imap_mdata_free; diff --git a/mailbox.c b/mailbox.c index f759c8e5f..3978614e6 100644 --- a/mailbox.c +++ b/mailbox.c @@ -111,6 +111,7 @@ void mailbox_free(struct Mailbox **ptr) FREE(&m->desc); if (m->mdata && m->free_mdata) m->free_mdata(&m->mdata); + FREE(&m->realpath); FREE(ptr); } diff --git a/mailbox.h b/mailbox.h index 2fde142f3..1d8d3e324 100644 --- a/mailbox.h +++ b/mailbox.h @@ -83,8 +83,7 @@ typedef uint16_t AclFlags; ///< Flags, e.g. #MUTT_ACL_ADMIN struct Mailbox { char path[PATH_MAX]; - char realpath[PATH_MAX]; /**< used for duplicate detection, context - * comparison, and the sidebar */ + char *realpath; ///< used for duplicate detection, context comparison, and the sidebar char *desc; off_t size; bool has_new; /**< mailbox has new mail */ diff --git a/mx.c b/mx.c index aa39dadcb..b545f7c16 100644 --- a/mx.c +++ b/mx.c @@ -1385,10 +1385,17 @@ int mx_path_canon2(struct Mailbox *m, const char *folder) if (!m) return -1; - if (m->realpath[0] == '\0') - mutt_str_strfcpy(m->realpath, m->path, sizeof(m->realpath)); + char buf[PATH_MAX]; + + if (m->realpath) + mutt_str_strfcpy(buf, m->realpath, sizeof(buf)); + else + mutt_str_strfcpy(buf, m->path, sizeof(buf)); + + int rc = mx_path_canon(buf, sizeof(buf), folder, &m->magic); + + mutt_str_replace(&m->realpath, buf); - int rc = mx_path_canon(m->realpath, sizeof(m->realpath), folder, &m->magic); if (rc >= 0) { m->mx_ops = mx_get_ops(m->magic); diff --git a/pop/pop.c b/pop/pop.c index e6101acec..94ef65d53 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -833,7 +833,7 @@ static int pop_mbox_open(struct Mailbox *m) url_tostring(&url, buf, sizeof(buf), 0); mutt_str_strfcpy(m->path, buf, sizeof(m->path)); - mutt_str_strfcpy(m->realpath, m->path, sizeof(m->realpath)); + mutt_str_replace(&m->realpath, m->path); struct PopAccountData *adata = m->account->adata; if (!adata) -- 2.40.0