From b80a4cf9a7f8276fabaf13a2c74ea777ed30031a Mon Sep 17 00:00:00 2001 From: hobbs Date: Wed, 17 Aug 2005 17:46:36 +0000 Subject: * generic/tclFCmd.c (TclFileMakeDirsCmd): fix to race condition in file mkdir (backport from head 2005-06-13) [Bug 1217375] --- ChangeLog | 5 +++++ generic/tclFCmd.c | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5a18b04..d311abd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-08-17 Jeff Hobbs + + * generic/tclFCmd.c (TclFileMakeDirsCmd): fix to race condition in + file mkdir (backport from head 2005-06-13) [Bug 1217375] + 2005-08-16 Kevin Kenny * generic/tclEvent.c (Tcl_Finalize): Pushed Tcl_FinalizeLoad and diff --git a/generic/tclFCmd.c b/generic/tclFCmd.c index a105f6e..0f4d1b0 100644 --- a/generic/tclFCmd.c +++ b/generic/tclFCmd.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclFCmd.c,v 1.20.2.1 2003/06/23 10:21:16 vincentdarley Exp $ + * RCS: @(#) $Id: tclFCmd.c,v 1.20.2.2 2005/08/17 17:46:36 hobbs Exp $ */ #include "tclInt.h" @@ -261,19 +261,45 @@ TclFileMakeDirsCmd(interp, objc, objv) errfile = target; goto done; } - } else if ((errno != ENOENT) - || (Tcl_FSCreateDirectory(target) != TCL_OK)) { + } else if (errno != ENOENT) { + /* + * If Tcl_FSStat() failed and the error is anything + * other than non-existence of the target, throw the + * error. + */ errfile = target; goto done; + } else if (Tcl_FSCreateDirectory(target) != TCL_OK) { + /* + * Create might have failed because of being in a race + * condition with another process trying to create the + * same subdirectory. + */ + if (errno == EEXIST) { + if ((Tcl_FSStat(target, &statBuf) == 0) + && S_ISDIR(statBuf.st_mode)) { + /* + * It is a directory that wasn't there before, + * so keep going without error. + */ + Tcl_ResetResult(interp); + } else { + errfile = target; + goto done; + } + } else { + errfile = target; + goto done; + } } - /* Forget about this sub-path */ + /* Forget about this sub-path */ Tcl_DecrRefCount(target); target = NULL; } Tcl_DecrRefCount(split); split = NULL; } - + done: if (errfile != NULL) { Tcl_AppendResult(interp, "can't create directory \"", -- cgit v0.12