Atomic implementation of create file and obtain handle for Win/Symbian
authorJoão Abecasis <joao.abecasis@nokia.com>
Fri, 5 Aug 2011 08:45:08 +0000 (10:45 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 21 Oct 2011 20:20:18 +0000 (22:20 +0200)
commitf4f729cb7bccd8bc4812dd15855dfc5af4ff6c8c
tree681f214f3429836cca66905bdb58e4949e953f45
parenta4a09488ee979849f4e9b9b3b8590ad2a2472590
Atomic implementation of create file and obtain handle for Win/Symbian

Besides generating a unique name, createFileFromTemplate now also
acquires a file handle on all platforms. The file engine's native handle
is passed by reference and modified in place.

This fixes a long standing security issue on Windows.

On Windows and Symbian platforms we directly use the "native" file path
when processing the template and generating the unique name. Since the
native encoding is known, conversions at this point are safe.

Errors other than "file exists" are propagated to Q(Temporary)File,
and result in a failure in open(). The changes also unify error handling
and should give consistent behaviour across all platforms.

Worthy of note, there's a change in behaviour on Windows and Symbian:
fileNames returned by QTemporaryFile on Windows and Symbian are always
absolute after open has been called. This has to do with how
QFileSystemEntry::nativeFilePath works on these platforms. (Test was
updated to reflect change in behaviour.)

Reviewed-by: Gareth Stockwell
Reviewed-by: Shane Kearns
(cherry picked from commit ff9b69838ec146aeb43d4af8a03043f9c5f0454d)

Conflicts:

tests/auto/qtemporaryfile/tst_qtemporaryfile.cpp

Change-Id: Ibc9affb321ea4f4b193efc1f7336c9770b43d8df
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
src/corelib/io/qtemporaryfile.cpp
tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp