Commit f1800830 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

run git clang-format

parent b1149537
......@@ -8,8 +8,8 @@
#include <QCryptographicHash>
#include <QTest>
#include <QTemporaryDir>
#include <QTest>
QTEST_MAIN(MBoxBenchmark)
......@@ -83,7 +83,7 @@ void MBoxBenchmark::testProcfileLockPerformance()
MBox mbox2;
mbox2.setLockType(MBox::ProcmailLockfile);
mbox2.load(fileName());
mbox2.setUnlockTimeout(5000); // Keep the mbox locked for five seconds.
mbox2.setUnlockTimeout(5000); // Keep the mbox locked for five seconds.
const auto lst = mbox2.entries();
for (const MBoxEntry &entry : lst) {
......@@ -113,8 +113,7 @@ void MBoxBenchmark::voidTestMD5Performance()
QCryptographicHash hash(QCryptographicHash::Md5);
qint64 blockSize = 512 * 1024; // Read blocks of 512K
while (!file.atEnd())
{
while (!file.atEnd()) {
hash.addData(file.read(blockSize));
}
......
......@@ -9,9 +9,9 @@
#include <QDir>
#include <QFile>
#include <QTest>
#include <QStandardPaths>
#include <QTemporaryDir>
#include <QTest>
QTEST_MAIN(MboxTest)
......@@ -143,7 +143,7 @@ void MboxTest::testConcurrentAccess()
QVERIFY(false);
}
ThreadFillsMBox thread(fileName()); // locks the mbox file and adds a new message
ThreadFillsMBox thread(fileName()); // locks the mbox file and adds a new message
thread.start();
QVERIFY(mbox.load(fileName()));
......@@ -327,7 +327,7 @@ void MboxTest::testEntries()
infos2 = mbox1.entries(deletedEntries);
QCOMPARE(infos2.size(), 0);
QVERIFY(!deletedEntries.contains(MBoxEntry(10))); // some random offset
QVERIFY(!deletedEntries.contains(MBoxEntry(10))); // some random offset
infos2 = mbox1.entries(MBoxEntry::List() << MBoxEntry(10));
QCOMPARE(infos2.size(), 3);
QCOMPARE(infos2.at(0), infos.at(0));
......@@ -353,7 +353,7 @@ void MboxTest::testPurge()
MBox mbox2;
QVERIFY(mbox2.load(fileName()));
MBoxEntry::List list2 = mbox2.entries();
QCOMPARE(list2.size(), 2); // Is a message actually gone?
QCOMPARE(list2.size(), 2); // Is a message actually gone?
quint64 newOffsetSecondMessage = list.last().messageOffset() - list.at(1).messageOffset();
......@@ -374,7 +374,7 @@ void MboxTest::testPurge()
mbox1.purge(MBoxEntry::List() << list.at(0) << list.at(1));
QVERIFY(mbox2.load(fileName()));
list2 = mbox2.entries();
QCOMPARE(list2.size(), 1); // Are the messages actually gone?
QCOMPARE(list2.size(), 1); // Are the messages actually gone?
QCOMPARE(list2.first().messageOffset(), static_cast<quint64>(0));
// Third test: Delete all messages.
......@@ -391,7 +391,7 @@ void MboxTest::testPurge()
mbox1.purge(MBoxEntry::List() << list.at(0) << list.at(1) << list.at(2));
QVERIFY(mbox2.load(fileName()));
list2 = mbox2.entries();
QCOMPARE(list2.size(), 0); // Are the messages actually gone?
QCOMPARE(list2.size(), 0); // Are the messages actually gone?
}
void MboxTest::testLockTimeout()
......@@ -461,7 +461,7 @@ void MboxTest::testReadOnlyMbox()
// this still works since we could save it to a different file
MBoxEntry entry = mbox.appendMessage(mMail1);
QVERIFY(!mbox.save()); // original mbox is read-only
QVERIFY(!mbox.save()); // original mbox is read-only
// reading back the appended message (from memory)
QByteArray msg = mbox.readRawMessage(entry);
......@@ -472,10 +472,10 @@ void MboxTest::testReadOnlyMbox()
msg = mbox.readRawMessage(list.at(0));
QVERIFY(!msg.isEmpty());
QVERIFY(!mbox.purge(list)); // original mbox is read-only
QVERIFY(!mbox.purge(list)); // original mbox is read-only
QString tmpSaved = mTempDir->path() + QLatin1String("tempSaved.mbox");
QVERIFY(mbox.save(tmpSaved)); // other mbox file can be written
QVERIFY(mbox.save(tmpSaved)); // other mbox file can be written
MBox savedMbox;
savedMbox.setReadOnly();
......@@ -511,8 +511,7 @@ void ThreadFillsMBox::run()
file.open(QIODevice::WriteOnly | QIODevice::Append);
QByteArray message = KMime::CRLFtoLF(sEntry1);
file.write(QByteArray("From test@local.local ")
+QDateTime::currentDateTime().toString(Qt::ISODate).toUtf8() + "\n");
file.write(QByteArray("From test@local.local ") + QDateTime::currentDateTime().toString(Qt::ISODate).toUtf8() + "\n");
file.write(message);
file.write("\n\n");
file.close();
......
......@@ -42,7 +42,6 @@ MBox::~MBox()
}
d->close();
}
// Appended entries works as follows: When an mbox file is loaded from disk,
......@@ -57,8 +56,7 @@ MBoxEntry MBox::appendMessage(const KMime::Message::Ptr &entry)
const QByteArray rawEntry = MBoxPrivate::escapeFrom(entry->encodedContent());
if (rawEntry.size() <= 0) {
qCDebug(KMBOX_LOG) << "Message added to folder `" << d->mMboxFile.fileName()
<< "' contains no data. Ignoring it.";
qCDebug(KMBOX_LOG) << "Message added to folder `" << d->mMboxFile.fileName() << "' contains no data. Ignoring it.";
return MBoxEntry();
}
......@@ -66,7 +64,7 @@ MBoxEntry MBox::appendMessage(const KMime::Message::Ptr &entry)
// Make sure the byte array is large enough to check for an end character.
// Then check if the required newlines are there.
if (nextOffset < 1 && d->mMboxFile.size() > 0) { // Empty, add one empty line
if (nextOffset < 1 && d->mMboxFile.size() > 0) { // Empty, add one empty line
d->mAppendedEntries.append("\n");
++nextOffset;
} else if (nextOffset == 1 && d->mAppendedEntries.at(0) != '\n') {
......@@ -142,7 +140,7 @@ bool MBox::load(const QString &fileName)
return false;
}
d->mInitialMboxFileSize = d->mMboxFile.size(); // AFTER the file has been locked
d->mInitialMboxFileSize = d->mMboxFile.size(); // AFTER the file has been locked
QByteArray line;
QByteArray prevSeparator;
......@@ -155,8 +153,7 @@ bool MBox::load(const QString &fileName)
// if atEnd, use mail only if there was a separator line at all,
// otherwise it's not a valid mbox
if (d->isMBoxSeparator(line)
|| (d->mMboxFile.atEnd() && (prevSeparator.size() != 0))) {
if (d->isMBoxSeparator(line) || (d->mMboxFile.atEnd() && (prevSeparator.size() != 0))) {
// if we are the at the file end, update pos to not forget the last line
if (d->mMboxFile.atEnd()) {
pos = d->mMboxFile.pos();
......@@ -225,14 +222,12 @@ bool MBox::lock()
if (!d->mLockFileName.isEmpty()) {
args << QString::fromLocal8Bit(QFile::encodeName(d->mLockFileName));
} else {
args << QString::fromLocal8Bit(QFile::encodeName(d->mMboxFile.fileName()
+QLatin1String(".lock")));
args << QString::fromLocal8Bit(QFile::encodeName(d->mMboxFile.fileName() + QLatin1String(".lock")));
}
rc = QProcess::execute(QStringLiteral("lockfile"), args);
if (rc != 0) {
qCDebug(KMBOX_LOG) << "lockfile -l20 -r5 " << d->mMboxFile.fileName()
<< ": Failed (" << rc << ") switching to read only mode";
qCDebug(KMBOX_LOG) << "lockfile -l20 -r5 " << d->mMboxFile.fileName() << ": Failed (" << rc << ") switching to read only mode";
d->mReadOnly = true; // In case the MBox object was created read/write we
// set it to read only when locking failed.
} else {
......@@ -245,8 +240,7 @@ bool MBox::lock()
rc = QProcess::execute(QStringLiteral("mutt_dotlock"), args);
if (rc != 0) {
qCDebug(KMBOX_LOG) << "mutt_dotlock " << d->mMboxFile.fileName()
<< ": Failed (" << rc << ") switching to read only mode";
qCDebug(KMBOX_LOG) << "mutt_dotlock " << d->mMboxFile.fileName() << ": Failed (" << rc << ") switching to read only mode";
d->mReadOnly = true; // In case the MBox object was created read/write we
// set it to read only when locking failed.
} else {
......@@ -255,8 +249,7 @@ bool MBox::lock()
break;
case MuttDotlockPrivileged:
args << QStringLiteral("-p")
<< QString::fromLocal8Bit(QFile::encodeName(d->mMboxFile.fileName()));
args << QStringLiteral("-p") << QString::fromLocal8Bit(QFile::encodeName(d->mMboxFile.fileName()));
rc = QProcess::execute(QStringLiteral("mutt_dotlock"), args);
if (rc != 0) {
......@@ -278,7 +271,7 @@ bool MBox::lock()
if (d->mFileLocked) {
if (!d->open()) {
const bool unlocked = unlock();
Q_ASSERT(unlocked); // If this fails we're in trouble.
Q_ASSERT(unlocked); // If this fails we're in trouble.
Q_UNUSED(unlocked)
}
}
......@@ -345,9 +338,7 @@ bool MBox::purge(const MBoxEntry::List &deletedEntries, QVector<MBoxEntry::Pair>
if (deletedEntries.contains(entry) && !writeOffSetInitialized) {
writeOffset = entry.messageOffset();
writeOffSetInitialized = true;
} else if (writeOffSetInitialized
&& writeOffset < entry.messageOffset()
&& !deletedEntries.contains(entry)) {
} else if (writeOffSetInitialized && writeOffset < entry.messageOffset() && !deletedEntries.contains(entry)) {
// The current message doesn't have to be deleted, but must be moved.
// First determine the size of the entry that must be moved.
quint64 entrySize = 0;
......@@ -358,7 +349,7 @@ bool MBox::purge(const MBoxEntry::List &deletedEntries, QVector<MBoxEntry::Pair>
entrySize = origFileSize - entry.messageOffset();
}
Q_ASSERT(entrySize > 0); // MBox entries really cannot have a size <= 0;
Q_ASSERT(entrySize > 0); // MBox entries really cannot have a size <= 0;
// we map the whole area of the file starting at the writeOffset up to the
// message that have to be moved into memory. This includes eventually the
......@@ -381,8 +372,7 @@ bool MBox::purge(const MBoxEntry::List &deletedEntries, QVector<MBoxEntry::Pair>
resultEntry.d->mMessageSize = entry.messageSize();
resultingEntryList << resultEntry;
tmpMovedEntries << MBoxEntry::Pair(MBoxEntry(entry.messageOffset()),
MBoxEntry(resultEntry.messageOffset()));
tmpMovedEntries << MBoxEntry::Pair(MBoxEntry(entry.messageOffset()), MBoxEntry(resultEntry.messageOffset()));
writeOffset += entrySize;
} else if (!deletedEntries.contains(entry)) {
// Unmoved and not deleted entry, can only ocure before the first deleted
......@@ -661,14 +651,12 @@ bool MBox::unlock()
break;
case MuttDotlock:
args << QStringLiteral("-u")
<< QString::fromLocal8Bit(QFile::encodeName(d->mMboxFile.fileName()));
args << QStringLiteral("-u") << QString::fromLocal8Bit(QFile::encodeName(d->mMboxFile.fileName()));
rc = QProcess::execute(QStringLiteral("mutt_dotlock"), args);
break;
case MuttDotlockPrivileged:
args << QStringLiteral("-u") << QStringLiteral("-p")
<< QString::fromLocal8Bit(QFile::encodeName(d->mMboxFile.fileName()));
args << QStringLiteral("-u") << QStringLiteral("-p") << QString::fromLocal8Bit(QFile::encodeName(d->mMboxFile.fileName()));
rc = QProcess::execute(QStringLiteral("mutt_dotlock"), args);
break;
......@@ -677,7 +665,7 @@ bool MBox::unlock()
break;
}
if (rc == 0) { // Unlocking succeeded
if (rc == 0) { // Unlocking succeeded
d->mFileLocked = false;
}
......
......@@ -13,7 +13,8 @@
#include <kmime/kmime_message.h>
namespace KMBox {
namespace KMBox
{
class MBoxPrivate;
/**
......@@ -28,12 +29,7 @@ public:
/**
* Describes the type of locking that will be used.
*/
enum LockType {
ProcmailLockfile,
MuttDotlock,
MuttDotlockPrivileged,
None
};
enum LockType { ProcmailLockfile, MuttDotlock, MuttDotlockPrivileged, None };
/**
* Creates a new mbox object.
......
......@@ -7,8 +7,8 @@
#include "mbox_p.h"
#include "kmbox_debug.h"
#include <QUrl>
#include <QLocale>
#include <QUrl>
using namespace KMBox;
......@@ -30,16 +30,15 @@ MBoxPrivate::~MBoxPrivate()
bool MBoxPrivate::open()
{
if (mMboxFile.isOpen()) {
return true; // already open
return true; // already open
}
QIODevice::OpenMode mode = mReadOnly ? QIODevice::ReadOnly : QIODevice::ReadWrite;
if (!mMboxFile.open(mode)) { // messages file
if (!mMboxFile.open(mode)) { // messages file
// failed to open readWrite -> try to open readOnly
if (!mMboxFile.open(QIODevice::ReadOnly)) {
qCDebug(KMBOX_LOG) << "Cannot open mbox file `" << mMboxFile.fileName() << "' FileError:"
<< mMboxFile.errorString();
qCDebug(KMBOX_LOG) << "Cannot open mbox file `" << mMboxFile.fileName() << "' FileError:" << mMboxFile.errorString();
return false;
} else {
mReadOnly = true;
......@@ -112,7 +111,7 @@ QByteArray MBoxPrivate::mboxMessageSeparator(const QByteArray &msg)
return separator;
}
#define STRDIM(x) (sizeof(x)/sizeof(*x)-1)
#define STRDIM(x) (sizeof(x) / sizeof(*x) - 1)
QByteArray MBoxPrivate::escapeFrom(const QByteArray &str)
{
......@@ -178,10 +177,10 @@ void MBoxPrivate::unescapeFrom(char *str, size_t strLen)
const char *const e = str + strLen - STRDIM(">From ");
while (s < e) {
if (*s == '\n' && *(s + 1) == '>') { // we can do the lookahead,
if (*s == '\n' && *(s + 1) == '>') { // we can do the lookahead,
// since e is 6 chars from the end!
*d++ = *s++; // == '\n'
*d++ = *s++; // == '>'
*d++ = *s++; // == '\n'
*d++ = *s++; // == '>'
while (s < e && *s == '>') {
*d++ = *s++;
......@@ -199,14 +198,14 @@ void MBoxPrivate::unescapeFrom(char *str, size_t strLen)
*d++ = *s++;
}
if (d < s) { // only NUL-terminate if it's shorter
if (d < s) { // only NUL-terminate if it's shorter
*d = 0;
}
}
bool MBoxPrivate::isMBoxSeparator(const QByteArray &line) const
{
if (!line.startsWith("From ")) { //krazy:exclude=strings
if (!line.startsWith("From ")) { // krazy:exclude=strings
return false;
}
......
......@@ -13,7 +13,8 @@
#include <QObject>
#include <QTimer>
namespace KMBox {
namespace KMBox
{
class MBoxPrivate : public QObject
{
Q_OBJECT
......
......@@ -9,11 +9,12 @@
#include "kmbox_export.h"
#include <QVector>
#include <QPair>
#include <QSharedDataPointer>
#include <QVector>
namespace KMBox {
namespace KMBox
{
class MBoxEntryPrivate;
/**
* @short A class that encapsulates an entry of a MBox.
......
......@@ -9,7 +9,8 @@
#include <QSharedData>
namespace KMBox {
namespace KMBox
{
class MBoxEntryPrivate : public QSharedData
{
public:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment