diff options
author | Martin Smith <msmith@trolltech.com> | 2009-05-22 12:59:26 (GMT) |
---|---|---|
committer | Martin Smith <msmith@trolltech.com> | 2009-05-22 12:59:26 (GMT) |
commit | 1ee8715fe0dfa784be987cc0cfb4519b2f20adb0 (patch) | |
tree | 21004fd611096d062eb11f0cb9f87dfbb69d257a /src/corelib | |
parent | 751e0f1b70cb0c80e88f99e5137329d6f4b76562 (diff) | |
parent | 8b2a16bd7f434a159e34e93dbffc983927a0a143 (diff) | |
download | Qt-1ee8715fe0dfa784be987cc0cfb4519b2f20adb0.zip Qt-1ee8715fe0dfa784be987cc0cfb4519b2f20adb0.tar.gz Qt-1ee8715fe0dfa784be987cc0cfb4519b2f20adb0.tar.bz2 |
Merge branch '4.5' of git@scm.dev.nokia.troll.no:qt/qt into 4.5
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qfile.cpp | 30 | ||||
-rw-r--r-- | src/corelib/io/qfsfileengine.cpp | 9 | ||||
-rw-r--r-- | src/corelib/io/qprocess_unix.cpp | 23 | ||||
-rw-r--r-- | src/corelib/io/qtemporaryfile.cpp | 96 | ||||
-rw-r--r-- | src/corelib/kernel/qsharedmemory_unix.cpp | 4 | ||||
-rw-r--r-- | src/corelib/kernel/qsystemsemaphore_p.h | 4 | ||||
-rw-r--r-- | src/corelib/kernel/qtranslator.cpp | 4 | ||||
-rw-r--r-- | src/corelib/tools/qhash.h | 5 |
8 files changed, 114 insertions, 61 deletions
diff --git a/src/corelib/io/qfile.cpp b/src/corelib/io/qfile.cpp index d7da800..10b812b 100644 --- a/src/corelib/io/qfile.cpp +++ b/src/corelib/io/qfile.cpp @@ -718,38 +718,47 @@ QFile::rename(const QString &newName) return true; } - QFile in(fileName()); + if (isSequential()) { + d->setError(QFile::RenameError, tr("Will not rename sequential file using block copy")); + return false; + } + QFile out(newName); - if (in.open(QIODevice::ReadOnly)) { + if (open(QIODevice::ReadOnly)) { if (out.open(QIODevice::WriteOnly | QIODevice::Truncate)) { bool error = false; char block[4096]; - qint64 read; - while ((read = in.read(block, sizeof(block))) > 0) { - if (read != out.write(block, read)) { + qint64 bytes; + while ((bytes = read(block, sizeof(block))) > 0) { + if (bytes != out.write(block, bytes)) { d->setError(QFile::RenameError, out.errorString()); error = true; break; } } - if (read == -1) { - d->setError(QFile::RenameError, in.errorString()); + if (bytes == -1) { + d->setError(QFile::RenameError, errorString()); error = true; } if(!error) { - if (!in.remove()) { + if (!remove()) { d->setError(QFile::RenameError, tr("Cannot remove source file")); error = true; } } if (error) out.remove(); - else + else { + setPermissions(permissions()); + unsetError(); setFileName(newName); + } + close(); return !error; } + close(); } - d->setError(QFile::RenameError, out.isOpen() ? in.errorString() : out.errorString()); + d->setError(QFile::RenameError, out.isOpen() ? errorString() : out.errorString()); } return false; } @@ -908,6 +917,7 @@ QFile::copy(const QString &newName) out.setAutoRemove(false); #endif } + close(); } if(!error) { QFile::setPermissions(newName, permissions()); diff --git a/src/corelib/io/qfsfileengine.cpp b/src/corelib/io/qfsfileengine.cpp index 99c1909..e79d867 100644 --- a/src/corelib/io/qfsfileengine.cpp +++ b/src/corelib/io/qfsfileengine.cpp @@ -312,6 +312,10 @@ bool QFSFileEnginePrivate::openFh(QIODevice::OpenMode openMode, FILE *fh) if (ret == -1) { q->setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, qt_error_string(int(errno))); + + this->openMode = QIODevice::NotOpen; + this->fh = 0; + return false; } } @@ -335,6 +339,7 @@ bool QFSFileEngine::open(QIODevice::OpenMode openMode, int fd) if ((openMode & QFile::WriteOnly) && !(openMode & (QFile::ReadOnly | QFile::Append))) openMode |= QFile::Truncate; + d->openMode = openMode; d->lastFlushFailed = false; d->closeFileHandle = false; d->nativeFilePath.clear(); @@ -367,6 +372,10 @@ bool QFSFileEnginePrivate::openFd(QIODevice::OpenMode openMode, int fd) if (ret == -1) { q->setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, qt_error_string(int(errno))); + + this->openMode = QIODevice::NotOpen; + this->fd = -1; + return false; } } diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index 33d4a47..1fedd55 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -140,15 +140,6 @@ static void qt_native_close(int fd) } while (ret == -1 && errno == EINTR); } -static void qt_native_sigaction(int signum, const struct sigaction *act, - struct sigaction *oldact) -{ - int ret; - do { - ret = ::sigaction(signum, act, oldact); - } while (ret == -1 && errno == EINTR); -} - static void qt_native_dup2(int oldfd, int newfd) { int ret; @@ -255,7 +246,7 @@ QProcessManager::QProcessManager() memset(&action, 0, sizeof(action)); action.sa_handler = qt_sa_sigchld_handler; action.sa_flags = SA_NOCLDSTOP; - qt_native_sigaction(SIGCHLD, &action, &oldAction); + ::sigaction(SIGCHLD, &action, &oldAction); if (oldAction.sa_handler != qt_sa_sigchld_handler) qt_sa_old_sigchld_handler = oldAction.sa_handler; } @@ -282,9 +273,9 @@ QProcessManager::~QProcessManager() memset(&action, 0, sizeof(action)); action.sa_handler = qt_sa_old_sigchld_handler; action.sa_flags = SA_NOCLDSTOP; - qt_native_sigaction(SIGCHLD, &action, &oldAction); + ::sigaction(SIGCHLD, &action, &oldAction); if (oldAction.sa_handler != qt_sa_sigchld_handler) { - qt_native_sigaction(SIGCHLD, &oldAction, 0); + ::sigaction(SIGCHLD, &oldAction, 0); } } @@ -900,7 +891,7 @@ static void qt_ignore_sigpipe() struct sigaction noaction; memset(&noaction, 0, sizeof(noaction)); noaction.sa_handler = SIG_IGN; - qt_native_sigaction(SIGPIPE, &noaction, 0); + ::sigaction(SIGPIPE, &noaction, 0); } } @@ -1270,7 +1261,7 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a struct sigaction noaction; memset(&noaction, 0, sizeof(noaction)); noaction.sa_handler = SIG_IGN; - qt_native_sigaction(SIGPIPE, &noaction, 0); + ::sigaction(SIGPIPE, &noaction, 0); ::setsid(); @@ -1316,7 +1307,7 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a struct sigaction noaction; memset(&noaction, 0, sizeof(noaction)); noaction.sa_handler = SIG_IGN; - qt_native_sigaction(SIGPIPE, &noaction, 0); + ::sigaction(SIGPIPE, &noaction, 0); // '\1' means execv failed char c = '\1'; @@ -1327,7 +1318,7 @@ bool QProcessPrivate::startDetached(const QString &program, const QStringList &a struct sigaction noaction; memset(&noaction, 0, sizeof(noaction)); noaction.sa_handler = SIG_IGN; - qt_native_sigaction(SIGPIPE, &noaction, 0); + ::sigaction(SIGPIPE, &noaction, 0); // '\2' means internal error char c = '\2'; diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp index 6a9125c..b4d8a48 100644 --- a/src/corelib/io/qtemporaryfile.cpp +++ b/src/corelib/io/qtemporaryfile.cpp @@ -291,14 +291,22 @@ class QTemporaryFileEngine : public QFSFileEngine { Q_DECLARE_PRIVATE(QFSFileEngine) public: - QTemporaryFileEngine(const QString &file) : QFSFileEngine(file) { } + QTemporaryFileEngine(const QString &file, bool fileIsTemplate = true) + : QFSFileEngine(file), filePathIsTemplate(fileIsTemplate) + { + } + ~QTemporaryFileEngine(); + bool isReallyOpen(); void setFileName(const QString &file); bool open(QIODevice::OpenMode flags); bool remove(); + bool rename(const QString &newName); bool close(); + + bool filePathIsTemplate; }; QTemporaryFileEngine::~QTemporaryFileEngine() @@ -306,6 +314,21 @@ QTemporaryFileEngine::~QTemporaryFileEngine() QFSFileEngine::close(); } +bool QTemporaryFileEngine::isReallyOpen() +{ + Q_D(QFSFileEngine); + + if (!((0 == d->fh) && (-1 == d->fd) +#if defined Q_OS_WIN + && (INVALID_HANDLE_VALUE == d->fileHandle) +#endif + )) + return true; + + return false; + +} + void QTemporaryFileEngine::setFileName(const QString &file) { // Really close the file, so we don't leak @@ -316,13 +339,16 @@ void QTemporaryFileEngine::setFileName(const QString &file) bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode) { Q_D(QFSFileEngine); + Q_ASSERT(!isReallyOpen()); + + if (!filePathIsTemplate) + return QFSFileEngine::open(openMode); QString qfilename = d->filePath; if(!qfilename.contains(QLatin1String("XXXXXX"))) qfilename += QLatin1String(".XXXXXX"); int suffixLength = qfilename.length() - (qfilename.lastIndexOf(QLatin1String("XXXXXX"), -1, Qt::CaseSensitive) + 6); - d->closeFileHandle = true; char *filename = qstrdup(qfilename.toLocal8Bit()); #ifndef Q_WS_WIN @@ -330,16 +356,20 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode) if (fd != -1) { // First open the fd as an external file descriptor to // initialize the engine properly. - QFSFileEngine::open(openMode, fd); + if (QFSFileEngine::open(openMode, fd)) { - // Allow the engine to close the handle even if it's "external". - d->closeFileHandle = true; + // Allow the engine to close the handle even if it's "external". + d->closeFileHandle = true; - // Restore the file names (open() resets them). - d->filePath = QString::fromLocal8Bit(filename); //changed now! - d->nativeInitFileName(); - delete [] filename; - return true; + // Restore the file names (open() resets them). + d->filePath = QString::fromLocal8Bit(filename); //changed now! + filePathIsTemplate = false; + d->nativeInitFileName(); + delete [] filename; + return true; + } + + QT_CLOSE(fd); } delete [] filename; setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError, qt_error_string(errno)); @@ -351,6 +381,7 @@ bool QTemporaryFileEngine::open(QIODevice::OpenMode openMode) } d->filePath = QString::fromLocal8Bit(filename); + filePathIsTemplate = false; d->nativeInitFileName(); d->closeFileHandle = true; delete [] filename; @@ -364,9 +395,17 @@ bool QTemporaryFileEngine::remove() // Since the QTemporaryFileEngine::close() does not really close the file, // we must explicitly call QFSFileEngine::close() before we remove it. QFSFileEngine::close(); - bool removed = QFSFileEngine::remove(); - d->filePath.clear(); - return removed; + if (QFSFileEngine::remove()) { + d->filePath.clear(); + return true; + } + return false; +} + +bool QTemporaryFileEngine::rename(const QString &newName) +{ + QFSFileEngine::close(); + return QFSFileEngine::rename(newName); } bool QTemporaryFileEngine::close() @@ -388,17 +427,14 @@ protected: bool autoRemove; QString templateName; - mutable QTemporaryFileEngine *fileEngine; }; -QTemporaryFilePrivate::QTemporaryFilePrivate() : autoRemove(true), fileEngine(0) +QTemporaryFilePrivate::QTemporaryFilePrivate() : autoRemove(true) { } QTemporaryFilePrivate::~QTemporaryFilePrivate() { - delete fileEngine; - fileEngine = 0; } //************* QTemporaryFile @@ -430,8 +466,8 @@ QTemporaryFilePrivate::~QTemporaryFilePrivate() file will exist and be kept open internally by QTemporaryFile. The file name of the temporary file can be found by calling fileName(). - Note that this is only defined while the file is open; the function returns - an empty string before the file is opened and after it is closed. + Note that this is only defined after the file is first opened; the function + returns an empty string before this. A temporary file will have some static part of the name and some part that is calculated to be unique. The default filename \c @@ -601,7 +637,8 @@ void QTemporaryFile::setAutoRemove(bool b) QString QTemporaryFile::fileName() const { - if(!isOpen()) + Q_D(const QTemporaryFile); + if(d->fileName.isEmpty()) return QString(); return fileEngine()->fileName(QAbstractFileEngine::DefaultName); } @@ -695,8 +732,12 @@ QTemporaryFile *QTemporaryFile::createLocalFile(QFile &file) QAbstractFileEngine *QTemporaryFile::fileEngine() const { Q_D(const QTemporaryFile); - if(!d->fileEngine) - d->fileEngine = new QTemporaryFileEngine(d->templateName); + if(!d->fileEngine) { + if (d->fileName.isEmpty()) + d->fileEngine = new QTemporaryFileEngine(d->templateName); + else + d->fileEngine = new QTemporaryFileEngine(d->fileName, false); + } return d->fileEngine; } @@ -711,10 +752,13 @@ bool QTemporaryFile::open(OpenMode flags) { Q_D(QTemporaryFile); if (!d->fileName.isEmpty()) { - setOpenMode(flags); - return true; + if (static_cast<QTemporaryFileEngine*>(fileEngine())->isReallyOpen()) { + setOpenMode(flags); + return true; + } } + flags |= QIODevice::ReadWrite; if (QFile::open(flags)) { d->fileName = d->fileEngine->fileName(QAbstractFileEngine::DefaultName); return true; @@ -722,6 +766,8 @@ bool QTemporaryFile::open(OpenMode flags) return false; } +QT_END_NAMESPACE + #endif // QT_NO_TEMPORARYFILE -QT_END_NAMESPACE + diff --git a/src/corelib/kernel/qsharedmemory_unix.cpp b/src/corelib/kernel/qsharedmemory_unix.cpp index 487c653..61d56f4 100644 --- a/src/corelib/kernel/qsharedmemory_unix.cpp +++ b/src/corelib/kernel/qsharedmemory_unix.cpp @@ -49,10 +49,10 @@ #include <errno.h> -QT_BEGIN_NAMESPACE - #ifndef QT_NO_SHAREDMEMORY +QT_BEGIN_NAMESPACE + #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> diff --git a/src/corelib/kernel/qsystemsemaphore_p.h b/src/corelib/kernel/qsystemsemaphore_p.h index 81d4f10..a4a7389 100644 --- a/src/corelib/kernel/qsystemsemaphore_p.h +++ b/src/corelib/kernel/qsystemsemaphore_p.h @@ -101,9 +101,9 @@ public: QSystemSemaphore::SystemSemaphoreError error; }; -#endif // QT_NO_SYSTEMSEMAPHORE +QT_END_NAMESPACE +#endif // QT_NO_SYSTEMSEMAPHORE -QT_END_NAMESPACE #endif // QSYSTEMSEMAPHORE_P_H diff --git a/src/corelib/kernel/qtranslator.cpp b/src/corelib/kernel/qtranslator.cpp index 77d6599..3e4b467 100644 --- a/src/corelib/kernel/qtranslator.cpp +++ b/src/corelib/kernel/qtranslator.cpp @@ -819,6 +819,6 @@ bool QTranslator::isEmpty() const Use translate(\a context, \a sourceText, \a comment) instead. */ -#endif // QT_NO_TRANSLATION - QT_END_NAMESPACE + +#endif // QT_NO_TRANSLATION diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index a18b531..632c422 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -97,10 +97,7 @@ Q_CORE_EXPORT uint qHash(const QBitArray &key); #endif template <class T> inline uint qHash(const T *key) { - if (sizeof(const T *) > sizeof(uint)) - return qHash(reinterpret_cast<quint64>(key)); - else - return uint(reinterpret_cast<ulong>(key)); + return qHash(reinterpret_cast<quintptr>(key)); } #if defined(Q_CC_MSVC) #pragma warning( pop ) |