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>
bb10
João Abecasis 2011-08-05 10:49:44 +02:00 committed by Qt by Nokia
parent 69dd45c2d8
commit c9fde0d590
1 changed files with 3 additions and 27 deletions

View File

@ -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)