From c9fde0d5902b3cee6cdd1514026d5ab04126f505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 5 Aug 2011 10:49:44 +0200 Subject: Use "native paths" on POSIX platforms as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/corelib/io/qtemporaryfile.cpp | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) (limited to 'src/corelib/io') 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) -- cgit v1.2.3