summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2011-08-05 10:49:44 +0200
committerQt by Nokia <qt-info@nokia.com>2011-10-21 22:20:34 +0200
commitc9fde0d5902b3cee6cdd1514026d5ab04126f505 (patch)
tree263520b1e5774e25029e8a0fe51d1d6969f6ea09 /src
parent69dd45c2d8a1a548b257693f6fdb6f1925d7f39f (diff)
Use "native paths" on POSIX platforms as well
And don't rely solely on "local8Bit" conversions. QFile defines an API for overriding how encoding conversions are done for filenames. In generating unique names, QTemporaryFile ignored that API and hardcoded the use of local 8-bit, implicitly assuming that that was appropriate. With this change, we switch that assumption to one where user supplied encoding function keeps the byte value of 'X' and '/', also assuming that encoded 'X' takes up a single-byte (i.e., the byte sequence for "XXXXXX" remains unchanged). There was also, and there still is an assumption in name generation that byte values for ASCII alpha-numeric characters are valid in the "native" encoding. In practice this change is compatible with UTF-8, Latin-1 and other ISO/IEC 8859 encodings. At any rate, it's very likely that only UTF-8 is relevant here. Reviewed-by: Denis Dzyubenko (cherry picked from commit 0de701d01cb221464eed773fd3751aff73fe4d60) Change-Id: I9ee0fe8e3cad48694d5ec9a2bedd5412cfc0d172 Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qtemporaryfile.cpp30
1 files changed, 3 insertions, 27 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index b86dbf9090..82d67ab644 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -366,14 +366,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
if (!filePathIsTemplate)
return QFSFileEngine::open(openMode);
- const QString qfilename =
-#if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
- // Since the native encoding is out of our control, we need to process
- // the path as UTF-16 before doing any conversions
- d->fileEntry.filePath();
-#else
- d->fileEntry.nativeFilePath();
-#endif
+ const QFileSystemEntry::NativePath qfilename = d->fileEntry.nativeFilePath();
// Find placeholder string.
uint phPos = qfilename.length();
@@ -382,7 +375,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
while (phPos != 0) {
--phPos;
- if (qfilename[phPos] == QLatin1Char('X')) {
+ if (qfilename[phPos] == Latin1Char('X')) {
++phLength;
continue;
}
@@ -390,7 +383,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
if (phLength >= 6
|| qfilename[phPos] ==
#if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
- QLatin1Char('/')
+ '/'
#else
QLatin1Char('\\')
#endif
@@ -404,29 +397,12 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode)
QFileSystemEntry::NativePath filename;
-#if !defined(Q_OS_WIN) && !defined(Q_OS_SYMBIAN)
- if (phLength < 6) {
- filename = qfilename.toLocal8Bit();
-
- phPos = filename.length() + 1; // Account for added dot in prefix
- phLength = 6;
- filename = filename % '.' % Placeholder(phLength);
- } else {
- QByteArray prefix, suffix;
- prefix = qfilename.leftRef(phPos).toLocal8Bit();
- suffix = qfilename.midRef(phPos + phLength).toLocal8Bit();
-
- phPos = prefix.length();
- filename = prefix % Placeholder(phLength) % suffix;
- }
-#else
if (phLength < 6) {
phPos = qfilename.length() + 1; // Account for added dot in prefix
phLength = 6;
filename = qfilename % Latin1Char('.') % Placeholder(phLength);
} else
filename = qfilename;
-#endif
QSystemError error;
#if defined(Q_OS_WIN)