NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: PR/47577 CVS commit: src/usr.bin/mail



Hello,

 | Committed By:        christos
 | Date:                Tue Feb 19 17:43:33 UTC 2013
 | 
 | Modified Files:
 |      src/usr.bin/mail: fio.c glob.h lex.c
 | 
 | Log Message:
 | PR/47577: Steffen "Daode" Nurpmeso: Keep a resolved folder name together
 | with a display name in order to keep track of current state when the \
 |directory
 | is changed.

I'm not happy with the code after all -- it doesn't recognize
concurrent changes of the *folder* option (and assign() and
unset() do not check for special variables to perform necessary
updates).
So here is a refinement which is of smaller code size and prints
correct results even if *folder* is modified on the fly.
Thanks

--steffen

--- fio.c.orig  2013-02-19 06:58:25.000000000 +0100
+++ fio.c       2013-02-19 07:09:47.000000000 +0100
@@ -397,15 +397,15 @@ getfold(char *name, size_t namesize)
 
        if ((folder = value(ENAME_FOLDER)) == NULL)
                return -1;
-       if (*folder == '/')
-               (void)strlcpy(unres, folder, sizeof(unres));
-       else
+       if (*folder != '/') {
                (void)snprintf(unres, sizeof(unres), "%s/%s", homedir, folder);
-       if (realpath(unres, res) == NULL) {
-               warn("Can't canonicalize folder `%s'", unres);
-               (void)strlcpy(name, unres, namesize);
-       } else
-               (void)strlcpy(name, res, namesize);
+               folder = unres;
+       }
+       if (realpath(folder, res) == NULL)
+               warn("Can't canonicalize folder `%s'", folder);
+       else
+               folder = res;
+       (void)strlcpy(name, folder, namesize);
        return 0;
 }
 
--- lex.c.orig  2013-02-19 06:58:25.000000000 +0100
+++ lex.c       2013-02-19 07:09:47.000000000 +0100
@@ -147,7 +147,8 @@ update_mailname(const char *name)
        char tbuf[PATHSIZE];
        size_t l;
 
-       if (realpath(name, mailname) == NULL) {
+       /* Don't realpath(3) if it's only an update request */
+       if (name != NULL && realpath(name, mailname) == NULL) {
                warn("Can't canonicalize `%s'", name);
                return;
        }
@@ -272,8 +273,7 @@ setfile(const char *name)
        shudclob = 1;
        edit = isedit;
        (void)strcpy(prevfile, mailname);
-       if (name != mailname)
-               update_mailname(name);
+       update_mailname(name != mailname ? name : NULL);
        mailsize = fsize(ibuf);
        (void)snprintf(tempname, sizeof(tempname),
            "%s/mail.RxXXXXXXXXXX", tmpdir);
@@ -1057,6 +1057,7 @@ newfileinfo(int omsgCount)
        /*
         * Display the statistics.
         */
+       update_mailname(NULL);
        (void)printf("\"%s\": ", displayname);
        {
                int cnt = get_abs_msgCount();


Home | Main Index | Thread Index | Old Index