From fb234cc16f1101ed2189ceb578b7d5f1f79ebe72 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sun, 16 Oct 2016 03:21:42 +0200
Subject: 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 17b1b66..77c7026 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -1755,6 +1755,7 @@ struct fd *open_fd( struct fd *root, const char *name, int flags, mode_t *mode,
     struct fd *fd;
     int root_fd = -1;
     int rw_mode;
+    int created = (flags & O_CREAT);
 
     if (((options & FILE_DELETE_ON_CLOSE) && !(access & DELETE)) ||
         ((options & FILE_DIRECTORY_FILE) && (flags & O_TRUNC)))
@@ -1793,6 +1794,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);
     }
@@ -1865,7 +1867,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.9.0

