From: Brendan Cully Date: Fri, 6 Apr 2007 19:54:46 +0000 (-0700) Subject: Make safe_open with O_EXCL friendlier for NFS. X-Git-Tag: mutt-1-5-15-rel~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d086df8820f3f70333b42a66027458fb5e286712;p=mutt Make safe_open with O_EXCL friendlier for NFS. Per #2707, when an open file is moved into a different directory over NFS, it may leave a .nfsXXX hardlink behind. This causes the rmdir in safe_open to fail, leaving tempdir droppings around. This patch works around the problem by closing the file after creating it and reopening it after rename. --- diff --git a/lib.c b/lib.c index e6e80c2e..a0cbca22 100644 --- a/lib.c +++ b/lib.c @@ -575,18 +575,15 @@ int safe_open (const char *path, int flags) rmdir (safe_dir); return fd; } - + + /* NFS and I believe cygwin do not handle movement of open files well */ + close (fd); if (mutt_put_file_in_place (path, safe_file, safe_dir) == -1) - { - close (fd); return -1; - } - } - else - { - if ((fd = open (path, flags, 0600)) < 0) - return fd; } + + if ((fd = open (path, flags & ~O_EXCL, 0600)) < 0) + return fd; /* make sure the file is not symlink */ if (lstat (path, &osb) < 0 || fstat (fd, &nsb) < 0 ||