From a1e20681a032f9f3ce4c47922ee8509891401691 Mon Sep 17 00:00:00 2001
From: sebres <sebres@users.sourceforge.net>
Date: Fri, 6 Apr 2018 17:28:56 +0000
Subject: [PATCH 1079/1800] =?UTF-8?q?[27b682284974d0cd]=20command=20"file?=
 =?UTF-8?q?=20delete":=20avoid=20possible=20race=20condition=20if=20file/d?=
 =?UTF-8?q?irectory=20deleted=20after=20call=20of=20lstat,=20so=20bypass?=
 =?UTF-8?q?=20ENOENT=20error=20code.=20Thanks=20to=20Rainer=20M=C3=BCller?=
 =?UTF-8?q?=20(aka=20raimue)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 generic/tclFCmd.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/generic/tclFCmd.c b/generic/tclFCmd.c
index c52cd1e7e..5b2fbe1fa 100644
--- a/generic/tclFCmd.c
+++ b/generic/tclFCmd.c
@@ -373,14 +373,7 @@ TclFileDeleteCmd(
 	 */
 
 	if (Tcl_FSLstat(objv[i], &statBuf) != 0) {
-	    /*
-	     * Trying to delete a file that does not exist is not considered
-	     * an error, just a no-op
-	     */
-
-	    if (errno != ENOENT) {
-		result = TCL_ERROR;
-	    }
+	    result = TCL_ERROR;
 	} else if (S_ISDIR(statBuf.st_mode)) {
 	    /*
 	     * We own a reference count on errorBuffer, if it was set as a
@@ -416,8 +409,15 @@ TclFileDeleteCmd(
 	}
 
 	if (result != TCL_OK) {
-	    result = TCL_ERROR;
 
+	    /*
+	     * Avoid possible race condition (file/directory deleted after call
+	     * of lstat), so bypass ENOENT because not an error, just a no-op
+	     */
+	    if (errno == ENOENT) {
+		result = TCL_OK;
+		continue;
+	    }
 	    /*
 	     * It is important that we break on error, otherwise we might end
 	     * up owning reference counts on numerous errorBuffers.
-- 
2.19.1

