diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2011-03-25 17:13:04 (GMT) |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2011-04-04 11:22:48 (GMT) |
commit | 2c3d675b97c52ad925891de16d2ea9dcfa9fae4c (patch) | |
tree | 76c2ae667f6c9cc40de38120b2f6a2e2cdec2d54 /src/corelib/io | |
parent | 1c09fc7013f0058ff96c52a39637d0167d084dce (diff) | |
download | Qt-2c3d675b97c52ad925891de16d2ea9dcfa9fae4c.zip Qt-2c3d675b97c52ad925891de16d2ea9dcfa9fae4c.tar.gz Qt-2c3d675b97c52ad925891de16d2ea9dcfa9fae4c.tar.bz2 |
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
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qtemporaryfile.cpp | 35 |
1 files changed, 0 insertions, 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 <errno.h> -# include <sys/stat.h> -# include <sys/types.h> #endif #include <stdlib.h> @@ -67,10 +65,6 @@ # include <process.h> #endif -#if defined(Q_OS_WINCE) -# include <types.h> -#endif - #if defined(Q_OS_VXWORKS) # include <taskLib.h> #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 { |