diff options
author | hobbs <hobbs> | 2005-08-17 17:46:36 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2005-08-17 17:46:36 (GMT) |
commit | 30d1f3f37b544e2858ce6747d90757074db2695b (patch) | |
tree | a325eeb373d9d01ef62092b7865710973ef4d2e0 /generic/tclFCmd.c | |
parent | bb2e8a4f33d6098ada76de6e14ce9d74cfd9696e (diff) | |
download | tcl-30d1f3f37b544e2858ce6747d90757074db2695b.zip tcl-30d1f3f37b544e2858ce6747d90757074db2695b.tar.gz tcl-30d1f3f37b544e2858ce6747d90757074db2695b.tar.bz2 |
* generic/tclFCmd.c (TclFileMakeDirsCmd): fix to race condition in
file mkdir (backport from head 2005-06-13) [Bug 1217375]
Diffstat (limited to 'generic/tclFCmd.c')
-rw-r--r-- | generic/tclFCmd.c | 36 |
1 files changed, 31 insertions, 5 deletions
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 \"", |