]> git.marmaro.de Git - mmh/commitdiff
Fix two errors in the conversion to m_mktemp2():
authorKen Hornstein <kenh@pobox.com>
Wed, 11 Jan 2012 19:48:45 +0000 (14:48 -0500)
committerKen Hornstein <kenh@pobox.com>
Wed, 11 Jan 2012 19:48:45 +0000 (14:48 -0500)
- There was an off-by-one error that prevented the temporary file
  from being created in the same directory as the message it was being
  linked to.
- When using "dist", the assumption was that the temporary file would not
  exist when m_scratch was called (it wanted to link() to the name).  This
  was solved by simply unlink()ing the temporary file after it was created.

sbr/m_mktemp.c
uip/send.c
uip/whatnowsbr.c

index aa25636a95eda47cb12171d9fe5e845fe72a7f91..9f99119e1bb04fe88a5b8ad8894f862d596c346f 100644 (file)
@@ -121,7 +121,7 @@ m_mktemp2 (
         /* No directory component */
         return m_mktemp(pfx_in, fd_ret, fp_ret);
     }
-    n = (int)(cp-dir_in-1); /* Length of dir component */
+    n = (int)(cp-dir_in); /* Length of dir component */
     snprintf(buffer, sizeof(buffer), "%.*s%s", n, dir_in, pfx_in);
     return m_mktemp(buffer, fd_ret, fp_ret);
 }
index 39d425f57ba9c91f3c030978fd055fec4f2c6340..62bf60ae3fbd2cf6a90e1cffd73caec261310bc6 100644 (file)
@@ -426,6 +426,7 @@ go_to_it:
            && altmsg) {
        vec[vecp++] = "-dist";
        distfile = getcpy (m_mktemp2 (altmsg, invo_name, NULL, NULL));
+       unlink(distfile);
        if (link (altmsg, distfile) == NOTOK) {
            if (errno != EXDEV
 #ifdef EISREMOTE
index 7db5c58873e9d47ca981ca21ed02fa62db8d14e2..c3d93ff6b65e352f1c4ee7c70997e99454a4b5ab 100644 (file)
@@ -1313,6 +1313,7 @@ sendit (char *sp, char **arg, char *file, int pushed)
            && altmsg) {
        vec[vecp++] = "-dist";
        distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL));
+       unlink(distfile);
        if (link (altmsg, distfile) == NOTOK)
            adios (distfile, "unable to link %s to", altmsg);
     } else {