diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2011-08-05 08:49:44 (GMT) |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2011-08-17 15:52:23 (GMT) |
commit | 0de701d01cb221464eed773fd3751aff73fe4d60 (patch) | |
tree | 7229e2efc2bcc4519d0f686b80330ef30efc9089 /src/corelib | |
parent | a153d50eea2dea0925695a90af2c12f1887a9020 (diff) | |
download | Qt-0de701d01cb221464eed773fd3751aff73fe4d60.zip Qt-0de701d01cb221464eed773fd3751aff73fe4d60.tar.gz Qt-0de701d01cb221464eed773fd3751aff73fe4d60.tar.bz2 |
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
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qtemporaryfile.cpp | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 9f7cde2..ac5deac 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) |