diff options
author | kh1 <karsten.heimrich@digia.com> | 2014-06-23 13:15:15 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@digia.com> | 2014-06-24 10:31:08 +0200 |
commit | 924ebcdbc9b9e590a5f0905941e2d05ac34d4be2 (patch) | |
tree | e57fb26ece9f67e1c59f0967198350d0a511637a /src/libs/installer/fileutils.cpp | |
parent | 4d8d708f98172e0e49fb2f0aad2e22d7798318e5 (diff) |
Split out the file IO stuff and adjust other files respectively.
Also adjust the API to use QFileDevice instead of QIODevice to
make clear we just operate on files here and not on any possible
device like sockets, processes etc...
Change-Id: I4ecbb6e244fe4bb666ed12e62f9f5586bc1347f0
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
Diffstat (limited to 'src/libs/installer/fileutils.cpp')
-rw-r--r-- | src/libs/installer/fileutils.cpp | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/src/libs/installer/fileutils.cpp b/src/libs/installer/fileutils.cpp index 82639b7a6..76fae9d08 100644 --- a/src/libs/installer/fileutils.cpp +++ b/src/libs/installer/fileutils.cpp @@ -181,76 +181,6 @@ QString QInstaller::pathFromUrl(const QUrl &url) return str; } -void QInstaller::openForRead(QIODevice *dev, const QString &name) -{ - Q_ASSERT(dev); - if (!dev->open(QIODevice::ReadOnly)) - throw Error(QObject::tr("Cannot open file %1 for reading: %2").arg(name, dev->errorString())); -} - -void QInstaller::openForWrite(QIODevice *dev, const QString &name) -{ - Q_ASSERT(dev); - if (!dev->open(QIODevice::WriteOnly)) - throw Error(QObject::tr("Cannot open file %1 for writing: %2").arg(name, dev->errorString())); -} - -void QInstaller::openForAppend(QIODevice *dev, const QString &name) -{ - Q_ASSERT(dev); - if (!dev->open(QIODevice::WriteOnly | QIODevice::Append)) - throw Error(QObject::tr("Cannot open file %1 for writing: %2").arg(name, dev->errorString())); -} - -qint64 QInstaller::blockingWrite(QIODevice *out, const char *buffer, qint64 size) -{ - qint64 left = size; - while (left > 0) { - const qint64 n = out->write(buffer, left); - if (n < 0) { - throw Error(QObject::tr("Write failed after %1 bytes: %2").arg(QString::number(size-left), - out->errorString())); - } - left -= n; - } - return size; -} - -qint64 QInstaller::blockingWrite(QIODevice *out, const QByteArray &ba) -{ - return blockingWrite(out, ba.constData(), ba.size()); -} - -qint64 QInstaller::blockingRead(QIODevice *in, char *buffer, qint64 size) -{ - if (in->atEnd()) - return 0; - qint64 left = size; - while (left > 0) { - const qint64 n = in->read(buffer, left); - if (n < 0) { - throw Error(QObject::tr("Read failed after %1 bytes: %2").arg(QString::number(size-left), - in->errorString())); - } - left -= n; - buffer += n; - } - return size; -} - -void QInstaller::blockingCopy(QIODevice *in, QIODevice *out, qint64 size) -{ - static const qint64 blockSize = 4096; - QByteArray ba(blockSize, '\0'); - qint64 actual = qMin(blockSize, size); - while (actual > 0) { - blockingRead(in, ba.data(), actual); - blockingWrite(out, ba.constData(), actual); - size -= actual; - actual = qMin(blockSize, size); - } -} - void QInstaller::removeFiles(const QString &path, bool ignoreErrors) { const QFileInfoList entries = QDir(path).entryInfoList(QDir::AllEntries | QDir::Hidden); |