From 6b5ac1e9eaf73aa0d6dddf8e7f53bd9802a25f5b Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sun, 16 Oct 2016 03:21:42 +0200
Subject: [PATCH] server: Improve STATUS_CANNOT_DELETE checks for directory
 case.

---
 server/fd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/server/fd.c b/server/fd.c
index 784a8c08867..d238c43cf1f 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -1825,6 +1825,7 @@ struct fd *open_fd( struct fd *root, const char *name, int flags, mode_t *mode,
     int root_fd = -1;
     int rw_mode;
     char *path;
+    int created = (flags & O_CREAT);
 
     if (((options & FILE_DELETE_ON_CLOSE) && !(access & DELETE)) ||
         ((options & FILE_DIRECTORY_FILE) && (flags & O_TRUNC)))
@@ -1863,6 +1864,7 @@ struct fd *open_fd( struct fd *root, const char *name, int flags, mode_t *mode,
                 file_set_error();
                 goto error;
             }
+            created = 0;
         }
         flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
     }
@@ -1955,7 +1957,7 @@ struct fd *open_fd( struct fd *root, const char *name, int flags, mode_t *mode,
         }
 
         /* can't unlink files if we don't have permission to access */
-        if ((options & FILE_DELETE_ON_CLOSE) && !(flags & O_CREAT) &&
+        if ((options & FILE_DELETE_ON_CLOSE) && !created &&
             !(st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
         {
             set_error( STATUS_CANNOT_DELETE );
-- 
2.25.1

