From 2c3d675b97c52ad925891de16d2ea9dcfa9fae4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 25 Mar 2011 18:13:04 +0100 Subject: Don't pre-check if directory exists as it's unnecessary On Posix platforms, when attempting to atomically create file and obtain descriptor, we only continue if we get an EEXIST error. If the path points to a non-existing directory, we should get ENOENT and will fail as well. On Windows, the check was already ignored. We would detect the file does not exist, attempt to obtain a handle upon return to QTemporaryFileEngine::open and fail there without running "for a *very* long time". Checking if the directory exists beforehand is not only unnecessary it also constitutes a race condition. Trusting the result of this check is dangerous and doubly useless. Reviewed-by: Olivier Goffart Reviewed-by: Robin Burchell --- src/corelib/io/qtemporaryfile.cpp | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index bb38906..a9bed8b 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -51,8 +51,6 @@ #if !defined(Q_OS_WINCE) # include -# include -# include #endif #include @@ -67,10 +65,6 @@ # include #endif -#if defined(Q_OS_WINCE) -# include -#endif - #if defined(Q_OS_VXWORKS) # include #endif @@ -108,8 +102,6 @@ QT_BEGIN_NAMESPACE static int _gettemp(char *path, int slen) { char *start, *trv, *suffp; - QT_STATBUF sbuf; - int rval; #if defined(Q_OS_WIN) int pid; #else @@ -137,10 +129,6 @@ static int _gettemp(char *path, int slen) pid /= 10; } -#ifndef S_ISDIR -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#endif - while (trv >= path && *trv == 'X') { char c; @@ -154,29 +142,6 @@ static int _gettemp(char *path, int slen) } start = trv + 1; -#ifndef Q_OS_WIN - /* - * check the target directory; if you have six X's and it - * doesn't exist this runs for a *very* long time. - */ - for (;; --trv) { - if (trv <= path) - break; - if (*trv == '/') { - *trv = '\0'; - rval = QT_STAT(path, &sbuf); - *trv = '/'; - if (rval != 0) - return -1; - if (!S_ISDIR(sbuf.st_mode)) { - errno = ENOTDIR; - return -1; - } - break; - } - } -#endif - for (;;) { #ifndef Q_OS_WIN { -- cgit v0.12