X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/dd1c5703125bb10f78add2488ce32e83c523cfbb..f4bef2e06b4284481b3f900e853d1667f52eb37b:/uip/mhstoresbr.c diff --git a/uip/mhstoresbr.c b/uip/mhstoresbr.c index f5e3347d..b978dbfb 100644 --- a/uip/mhstoresbr.c +++ b/uip/mhstoresbr.c @@ -177,7 +177,7 @@ store_switch (CT ct) /* * Generic routine to store a MIME content. - * (audio, video, image, text, message/rfc922) + * (audio, video, image, text, message/rfc822) */ static int @@ -1129,7 +1129,7 @@ next_version (char *file, enum clobber_policy_t clobber_policy) { } for (version = 1; version < max_versions; ++version) { - struct stat st; + int fd; switch (clobber_policy) { case NMH_CLOBBER_AUTO: { @@ -1151,7 +1151,15 @@ next_version (char *file, enum clobber_policy_t clobber_policy) { return NULL; } - if (stat (buffer, &st) == NOTOK) { + /* Actually (try to) create the file here to avoid a race + condition on file naming + creation. This won't solve the + problem with old NFS that doesn't support O_EXCL, though. + Let the umask strip off permissions from 0666 as desired. + That's what fopen () would do if it was creating the file. */ + if ((fd = open (buffer, O_CREAT | O_EXCL, + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | + S_IROTH | S_IWOTH)) >= 0) { + close (fd); break; } } @@ -1220,7 +1228,7 @@ clobber_check (char *original_file) { if (stat (file, &st) == OK) { enum answers { NMH_YES, NMH_NO, NMH_RENAME }; static struct swit answer[4] = { - { "yes", 0 }, { "no", 0 }, { "rename", 0 }, { NULL, 0 } }; + { "yes", 0, NMH_YES }, { "no", 0, NMH_NO }, { "rename", 0, NMH_RENAME }, { NULL, 0, 0 } }; char **ans; if (isatty (fileno (stdin))) {