diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-02-16 10:31:30 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-02-16 10:39:59 +0100 |
commit | 9638d864a992bcbdb30b0baf5274072cef4125a5 (patch) | |
tree | 54be3b737721ad1e4d9e99726d75d4b06ece589d | |
parent | 768c1077b0d226d832f34904e929c2462eca158f (diff) | |
download | sink-9638d864a992bcbdb30b0baf5274072cef4125a5.tar.gz sink-9638d864a992bcbdb30b0baf5274072cef4125a5.zip |
Better debug output
-rw-r--r-- | examples/maildirresource/facade.cpp | 5 | ||||
-rw-r--r-- | examples/maildirresource/libmaildir/maildir.cpp | 75 |
2 files changed, 42 insertions, 38 deletions
diff --git a/examples/maildirresource/facade.cpp b/examples/maildirresource/facade.cpp index 13ceaaf..5ea3d98 100644 --- a/examples/maildirresource/facade.cpp +++ b/examples/maildirresource/facade.cpp | |||
@@ -28,6 +28,7 @@ MaildirResourceMailFacade::MaildirResourceMailFacade(const Sink::ResourceContext | |||
28 | : Sink::GenericFacade<Sink::ApplicationDomain::Mail>(context) | 28 | : Sink::GenericFacade<Sink::ApplicationDomain::Mail>(context) |
29 | { | 29 | { |
30 | mResultTransformation = [](Sink::ApplicationDomain::ApplicationDomainType &value) { | 30 | mResultTransformation = [](Sink::ApplicationDomain::ApplicationDomainType &value) { |
31 | Sink::Log::Context ctx{"maildirfacade"}; | ||
31 | if (value.hasProperty(Sink::ApplicationDomain::Mail::MimeMessage::name)) { | 32 | if (value.hasProperty(Sink::ApplicationDomain::Mail::MimeMessage::name)) { |
32 | auto mail = Sink::ApplicationDomain::Mail{value}; | 33 | auto mail = Sink::ApplicationDomain::Mail{value}; |
33 | const auto mimeMessage = mail.getMimeMessagePath(); | 34 | const auto mimeMessage = mail.getMimeMessagePath(); |
@@ -37,11 +38,11 @@ MaildirResourceMailFacade::MaildirResourceMailFacade(const Sink::ResourceContext | |||
37 | const auto folderPath = parts.join('/'); | 38 | const auto folderPath = parts.join('/'); |
38 | const auto path = folderPath + "/cur/"; | 39 | const auto path = folderPath + "/cur/"; |
39 | 40 | ||
40 | SinkTrace_("", "maildirfacade") << "Looking for mail in: " << path << key; | 41 | SinkTraceCtx(ctx) << "Looking for mail in: " << path << key; |
41 | QDir dir(path); | 42 | QDir dir(path); |
42 | const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files); | 43 | const QFileInfoList list = dir.entryInfoList(QStringList() << (key+"*"), QDir::Files); |
43 | if (list.size() != 1) { | 44 | if (list.size() != 1) { |
44 | SinkWarning_("", "maildirfacade") << "Failed to find message " << path << key << list.size(); | 45 | SinkErrorCtx(ctx) << "Failed to find message. Directory: " << path << "Key: " << key << "Number of matching files: " << list.size(); |
45 | mail.setProperty(Sink::ApplicationDomain::Mail::MimeMessage::name, QVariant()); | 46 | mail.setProperty(Sink::ApplicationDomain::Mail::MimeMessage::name, QVariant()); |
46 | } else { | 47 | } else { |
47 | mail.setMimeMessagePath(list.at(0).filePath()); | 48 | mail.setMimeMessagePath(list.at(0).filePath()); |
diff --git a/examples/maildirresource/libmaildir/maildir.cpp b/examples/maildirresource/libmaildir/maildir.cpp index c47e679..079bb10 100644 --- a/examples/maildirresource/libmaildir/maildir.cpp +++ b/examples/maildirresource/libmaildir/maildir.cpp | |||
@@ -25,6 +25,9 @@ | |||
25 | #include <QFileInfo> | 25 | #include <QFileInfo> |
26 | #include <QHostInfo> | 26 | #include <QHostInfo> |
27 | #include <QUuid> | 27 | #include <QUuid> |
28 | #include <QLoggingCategory> | ||
29 | |||
30 | Q_LOGGING_CATEGORY(log, "maildir"); | ||
28 | 31 | ||
29 | #include <time.h> | 32 | #include <time.h> |
30 | #include <unistd.h> | 33 | #include <unistd.h> |
@@ -108,7 +111,7 @@ public: | |||
108 | QString findRealKey(const QString& key) const | 111 | QString findRealKey(const QString& key) const |
109 | { | 112 | { |
110 | if (key.isEmpty()) { | 113 | if (key.isEmpty()) { |
111 | qWarning() << "Empty key: " << key; | 114 | qCWarning(log) << "Empty key: " << key; |
112 | return key; | 115 | return key; |
113 | } | 116 | } |
114 | if (QFile::exists(path + QString::fromLatin1("/cur/") + key)) { | 117 | if (QFile::exists(path + QString::fromLatin1("/cur/") + key)) { |
@@ -142,21 +145,21 @@ public: | |||
142 | bool moveAndRename(QDir &dest, const QString &newName) | 145 | bool moveAndRename(QDir &dest, const QString &newName) |
143 | { | 146 | { |
144 | if (!dest.exists()) { | 147 | if (!dest.exists()) { |
145 | qDebug() << "Destination does not exist"; | 148 | qCDebug(log) << "Destination does not exist"; |
146 | return false; | 149 | return false; |
147 | } | 150 | } |
148 | if (dest.exists(newName) || dest.exists(subDirNameForFolderName(newName))) { | 151 | if (dest.exists(newName) || dest.exists(subDirNameForFolderName(newName))) { |
149 | qDebug() << "New name already in use"; | 152 | qCDebug(log) << "New name already in use"; |
150 | return false; | 153 | return false; |
151 | } | 154 | } |
152 | 155 | ||
153 | if (!dest.rename(path, newName)) { | 156 | if (!dest.rename(path, newName)) { |
154 | qDebug() << "Failed to rename maildir"; | 157 | qCDebug(log) << "Failed to rename maildir"; |
155 | return false; | 158 | return false; |
156 | } | 159 | } |
157 | const QDir subDirs(Maildir::subDirPathForFolderPath(path)); | 160 | const QDir subDirs(Maildir::subDirPathForFolderPath(path)); |
158 | if (subDirs.exists() && !dest.rename(subDirs.path(), subDirNameForFolderName(newName))) { | 161 | if (subDirs.exists() && !dest.rename(subDirs.path(), subDirNameForFolderName(newName))) { |
159 | qDebug() << "Failed to rename subfolders"; | 162 | qCDebug(log) << "Failed to rename subfolders"; |
160 | return false; | 163 | return false; |
161 | } | 164 | } |
162 | 165 | ||
@@ -223,17 +226,17 @@ bool Maildir::Private::accessIsPossible(bool createMissingFolders) | |||
223 | Q_FOREACH (const QString &p, paths) { | 226 | Q_FOREACH (const QString &p, paths) { |
224 | if (!QFile::exists(p)) { | 227 | if (!QFile::exists(p)) { |
225 | if (!createMissingFolders) { | 228 | if (!createMissingFolders) { |
226 | qWarning() << QString("Error opening %1; this folder is missing.").arg(p); | 229 | qCWarning(log) << QString("Error opening %1; this folder is missing.").arg(p); |
227 | return false; | 230 | return false; |
228 | } | 231 | } |
229 | QDir().mkpath(p); | 232 | QDir().mkpath(p); |
230 | if (!QFile::exists(p)) { | 233 | if (!QFile::exists(p)) { |
231 | qWarning() << QString("Error opening %1; this folder is missing.").arg(p); | 234 | qCWarning(log) << QString("Error opening %1; this folder is missing.").arg(p); |
232 | return false; | 235 | return false; |
233 | } | 236 | } |
234 | } | 237 | } |
235 | if (!canAccess(p)) { | 238 | if (!canAccess(p)) { |
236 | qWarning() << QString("Error opening %1; either this is not a valid maildir folder, or you do not have sufficient access permissions.").arg(p); | 239 | qCWarning(log) << QString("Error opening %1; either this is not a valid maildir folder, or you do not have sufficient access permissions.").arg(p); |
237 | return false; | 240 | return false; |
238 | } | 241 | } |
239 | } | 242 | } |
@@ -375,7 +378,7 @@ QStringList Maildir::entryList() const | |||
375 | result += d->listNew(); | 378 | result += d->listNew(); |
376 | result += d->listCurrent(); | 379 | result += d->listCurrent(); |
377 | } | 380 | } |
378 | // qDebug() <<"Maildir::entryList()" << result; | 381 | // qCDebug(log) <<"Maildir::entryList()" << result; |
379 | return result; | 382 | return result; |
380 | } | 383 | } |
381 | 384 | ||
@@ -453,13 +456,13 @@ QByteArray Maildir::readEntry(const QString& key) const | |||
453 | 456 | ||
454 | QString realKey(d->findRealKey(key)); | 457 | QString realKey(d->findRealKey(key)); |
455 | if (realKey.isEmpty()) { | 458 | if (realKey.isEmpty()) { |
456 | qWarning() << "Maildir::readEntry unable to find: " << key; | 459 | qCWarning(log) << "Maildir::readEntry unable to find: " << key; |
457 | return result; | 460 | return result; |
458 | } | 461 | } |
459 | 462 | ||
460 | QFile f(realKey); | 463 | QFile f(realKey); |
461 | if (!f.open(QIODevice::ReadOnly)) { | 464 | if (!f.open(QIODevice::ReadOnly)) { |
462 | qWarning() << QString("Cannot open mail file %1.").arg(realKey); | 465 | qCWarning(log) << QString("Cannot open mail file %1.").arg(realKey); |
463 | return result; | 466 | return result; |
464 | } | 467 | } |
465 | 468 | ||
@@ -471,13 +474,13 @@ qint64 Maildir::size(const QString& key) const | |||
471 | { | 474 | { |
472 | QString realKey(d->findRealKey(key)); | 475 | QString realKey(d->findRealKey(key)); |
473 | if (realKey.isEmpty()) { | 476 | if (realKey.isEmpty()) { |
474 | qWarning() << "Maildir::size unable to find: " << key; | 477 | qCWarning(log) << "Maildir::size unable to find: " << key; |
475 | return -1; | 478 | return -1; |
476 | } | 479 | } |
477 | 480 | ||
478 | QFileInfo info(realKey); | 481 | QFileInfo info(realKey); |
479 | if (!info.exists()) { | 482 | if (!info.exists()) { |
480 | qWarning() << "Cannot open mail file:" << realKey; | 483 | qCWarning(log) << "Cannot open mail file:" << realKey; |
481 | return -1; | 484 | return -1; |
482 | } | 485 | } |
483 | 486 | ||
@@ -488,7 +491,7 @@ QDateTime Maildir::lastModified(const QString& key) const | |||
488 | { | 491 | { |
489 | const QString realKey(d->findRealKey(key)); | 492 | const QString realKey(d->findRealKey(key)); |
490 | if (realKey.isEmpty()) { | 493 | if (realKey.isEmpty()) { |
491 | qWarning() << "Maildir::lastModified unable to find: " << key; | 494 | qCWarning(log) << "Maildir::lastModified unable to find: " << key; |
492 | return QDateTime(); | 495 | return QDateTime(); |
493 | } | 496 | } |
494 | 497 | ||
@@ -506,7 +509,7 @@ void Maildir::importNewMails() | |||
506 | const QString filePath = QDir::fromNativeSeparators(entryIterator.next()); | 509 | const QString filePath = QDir::fromNativeSeparators(entryIterator.next()); |
507 | QFile file(filePath); | 510 | QFile file(filePath); |
508 | if (!file.rename(pathToCurrent() +"/" + entryIterator.fileName())) { | 511 | if (!file.rename(pathToCurrent() +"/" + entryIterator.fileName())) { |
509 | qWarning() << "Failed to rename the file: " << file.errorString(); | 512 | qCWarning(log) << "Failed to rename the file: " << file.errorString(); |
510 | } | 513 | } |
511 | } | 514 | } |
512 | } | 515 | } |
@@ -531,7 +534,7 @@ QByteArray Maildir::readEntryHeadersFromFile(const QString& file) | |||
531 | 534 | ||
532 | QFile f(file); | 535 | QFile f(file); |
533 | if (!f.open(QIODevice::ReadOnly)) { | 536 | if (!f.open(QIODevice::ReadOnly)) { |
534 | qWarning() << "Maildir::readEntryHeaders unable to find: " << file; | 537 | qCWarning(log) << "Maildir::readEntryHeaders unable to find: " << file; |
535 | return result; | 538 | return result; |
536 | } | 539 | } |
537 | f.map(0, qMin((qint64)8000, f.size())); | 540 | f.map(0, qMin((qint64)8000, f.size())); |
@@ -548,7 +551,7 @@ QByteArray Maildir::readEntryHeaders(const QString& key) const | |||
548 | { | 551 | { |
549 | const QString realKey(d->findRealKey(key)); | 552 | const QString realKey(d->findRealKey(key)); |
550 | if (realKey.isEmpty()) { | 553 | if (realKey.isEmpty()) { |
551 | qWarning() << "Maildir::readEntryHeaders unable to find: " << key; | 554 | qCWarning(log) << "Maildir::readEntryHeaders unable to find: " << key; |
552 | return QByteArray(); | 555 | return QByteArray(); |
553 | } | 556 | } |
554 | 557 | ||
@@ -571,7 +574,7 @@ bool Maildir::writeEntry(const QString& key, const QByteArray& data) | |||
571 | { | 574 | { |
572 | QString realKey(d->findRealKey(key)); | 575 | QString realKey(d->findRealKey(key)); |
573 | if (realKey.isEmpty()) { | 576 | if (realKey.isEmpty()) { |
574 | qWarning() << "Maildir::writeEntry unable to find: " << key; | 577 | qCWarning(log) << "Maildir::writeEntry unable to find: " << key; |
575 | return false; | 578 | return false; |
576 | } | 579 | } |
577 | QFile f(realKey); | 580 | QFile f(realKey); |
@@ -579,7 +582,7 @@ bool Maildir::writeEntry(const QString& key, const QByteArray& data) | |||
579 | result = result & (f.write(data) != -1); | 582 | result = result & (f.write(data) != -1); |
580 | f.close(); | 583 | f.close(); |
581 | if (!result) { | 584 | if (!result) { |
582 | qWarning() << "Cannot write to mail file %1." << realKey; | 585 | qCWarning(log) << "Cannot write to mail file %1." << realKey; |
583 | return false; | 586 | return false; |
584 | } | 587 | } |
585 | return true; | 588 | return true; |
@@ -604,13 +607,13 @@ QString Maildir::addEntry(const QByteArray& data) | |||
604 | QFile f(key); | 607 | QFile f(key); |
605 | bool result = f.open(QIODevice::WriteOnly); | 608 | bool result = f.open(QIODevice::WriteOnly); |
606 | if (!result) { | 609 | if (!result) { |
607 | qWarning() << f.errorString(); | 610 | qCWarning(log) << f.errorString(); |
608 | qWarning() << "Cannot write to mail file: " << key; | 611 | qCWarning(log) << "Cannot write to mail file: " << key; |
609 | } | 612 | } |
610 | result = result & (f.write(data) != -1); | 613 | result = result & (f.write(data) != -1); |
611 | f.close(); | 614 | f.close(); |
612 | if (!result) { | 615 | if (!result) { |
613 | qWarning() << "Cannot write to mail file: " << key; | 616 | qCWarning(log) << "Cannot write to mail file: " << key; |
614 | return QString(); | 617 | return QString(); |
615 | } | 618 | } |
616 | /* | 619 | /* |
@@ -622,9 +625,9 @@ QString Maildir::addEntry(const QByteArray& data) | |||
622 | * | 625 | * |
623 | * For reference: http://trolltech.com/developer/task-tracker/index_html?method=entry&id=211215 | 626 | * For reference: http://trolltech.com/developer/task-tracker/index_html?method=entry&id=211215 |
624 | */ | 627 | */ |
625 | qDebug() << "New entry: " << finalKey; | 628 | qCDebug(log) << "New entry: " << finalKey; |
626 | if (!f.rename(finalKey)) { | 629 | if (!f.rename(finalKey)) { |
627 | qWarning() << "Maildir: Failed to add entry: " << finalKey << "! Error: " << f.errorString(); | 630 | qCWarning(log) << "Maildir: Failed to add entry: " << finalKey << "! Error: " << f.errorString(); |
628 | return QString(); | 631 | return QString(); |
629 | } | 632 | } |
630 | return uniqueKey; | 633 | return uniqueKey; |
@@ -648,13 +651,13 @@ QString Maildir::addEntryFromPath(const QString& path) | |||
648 | 651 | ||
649 | QFile f(path); | 652 | QFile f(path); |
650 | if (!f.open(QIODevice::ReadWrite)) { | 653 | if (!f.open(QIODevice::ReadWrite)) { |
651 | qWarning() << f.errorString(); | 654 | qCWarning(log) << f.errorString(); |
652 | qWarning() << "Cannot open mail file: " << key; | 655 | qCWarning(log) << "Cannot open mail file: " << key; |
653 | return QString(); | 656 | return QString(); |
654 | } | 657 | } |
655 | 658 | ||
656 | if (!f.rename(curKey)) { | 659 | if (!f.rename(curKey)) { |
657 | qWarning() << "Maildir: Failed to add entry: " << curKey << "! Error: " << f.errorString(); | 660 | qCWarning(log) << "Maildir: Failed to add entry: " << curKey << "! Error: " << f.errorString(); |
658 | return QString(); | 661 | return QString(); |
659 | } | 662 | } |
660 | return uniqueKey; | 663 | return uniqueKey; |
@@ -664,12 +667,12 @@ bool Maildir::removeEntry(const QString& key) | |||
664 | { | 667 | { |
665 | QString realKey(d->findRealKey(key)); | 668 | QString realKey(d->findRealKey(key)); |
666 | if (realKey.isEmpty()) { | 669 | if (realKey.isEmpty()) { |
667 | qWarning() << "Maildir::removeEntry unable to find: " << key; | 670 | qCWarning(log) << "Maildir::removeEntry unable to find: " << key; |
668 | return false; | 671 | return false; |
669 | } | 672 | } |
670 | QFile file(realKey); | 673 | QFile file(realKey); |
671 | if (!file.remove()) { | 674 | if (!file.remove()) { |
672 | qWarning() << file.errorString() << file.error(); | 675 | qCWarning(log) << file.errorString() << file.error(); |
673 | return false; | 676 | return false; |
674 | } | 677 | } |
675 | return true; | 678 | return true; |
@@ -678,9 +681,9 @@ bool Maildir::removeEntry(const QString& key) | |||
678 | QString Maildir::changeEntryFlags(const QString& key, const Maildir::Flags& flags) | 681 | QString Maildir::changeEntryFlags(const QString& key, const Maildir::Flags& flags) |
679 | { | 682 | { |
680 | QString realKey(d->findRealKey(key)); | 683 | QString realKey(d->findRealKey(key)); |
681 | qWarning() << "Change entiry flags: " << key << realKey; | 684 | qCWarning(log) << "Change entry flags: " << key << realKey; |
682 | if (realKey.isEmpty()) { | 685 | if (realKey.isEmpty()) { |
683 | qWarning() << "Maildir::changeEntryFlags unable to find: " << key; | 686 | qCWarning(log) << "Maildir::changeEntryFlags unable to find: " << key << "in " << d->path; |
684 | return QString(); | 687 | return QString(); |
685 | } | 688 | } |
686 | 689 | ||
@@ -713,7 +716,7 @@ QString Maildir::changeEntryFlags(const QString& key, const Maildir::Flags& flag | |||
713 | 716 | ||
714 | if (realKey == finalKey) { | 717 | if (realKey == finalKey) { |
715 | // Somehow it already is named this way (e.g. migration bug -> wrong status in sink) | 718 | // Somehow it already is named this way (e.g. migration bug -> wrong status in sink) |
716 | qWarning() << "File already named that way: " << newUniqueKey << finalKey; | 719 | qCWarning(log) << "File already named that way: " << newUniqueKey << finalKey; |
717 | return newUniqueKey; | 720 | return newUniqueKey; |
718 | } | 721 | } |
719 | 722 | ||
@@ -745,10 +748,10 @@ QString Maildir::changeEntryFlags(const QString& key, const Maildir::Flags& flag | |||
745 | } | 748 | } |
746 | 749 | ||
747 | if (!f.rename(finalKey)) { | 750 | if (!f.rename(finalKey)) { |
748 | qWarning() << "Maildir: Failed to rename entry: " << f.fileName() << " to " << finalKey << "! Error: " << f.errorString(); | 751 | qCWarning(log) << "Maildir: Failed to rename entry from: " << f.fileName() << " to " << finalKey << "! Error: " << f.errorString(); |
749 | return QString(); | 752 | return QString(); |
750 | } | 753 | } |
751 | qWarning() << "Renamed file: " << f.fileName() << finalKey; | 754 | qCDebug(log) << "Renamed file from: " << f.fileName() << " to " << finalKey; |
752 | 755 | ||
753 | return newUniqueKey; | 756 | return newUniqueKey; |
754 | } | 757 | } |
@@ -815,14 +818,14 @@ QString Maildir::moveEntryTo(const QString &key, const Maildir &destination) | |||
815 | { | 818 | { |
816 | const QString realKey(d->findRealKey(key)); | 819 | const QString realKey(d->findRealKey(key)); |
817 | if (realKey.isEmpty()) { | 820 | if (realKey.isEmpty()) { |
818 | qWarning() << "Unable to find: " << key; | 821 | qCWarning(log) << "Unable to find: " << key; |
819 | return QString(); | 822 | return QString(); |
820 | } | 823 | } |
821 | QFile f(realKey); | 824 | QFile f(realKey); |
822 | // ### is this safe regarding the maildir locking scheme? | 825 | // ### is this safe regarding the maildir locking scheme? |
823 | const QString targetKey = destination.path() + QDir::separator() + QLatin1String("cur") + QDir::separator() + key; | 826 | const QString targetKey = destination.path() + QDir::separator() + QLatin1String("cur") + QDir::separator() + key; |
824 | if (!f.rename(targetKey)) { | 827 | if (!f.rename(targetKey)) { |
825 | qWarning() << "Failed to rename" << realKey << "to" << targetKey << "! Error: " << f.errorString();; | 828 | qCWarning(log) << "Failed to rename" << realKey << "to" << targetKey << "! Error: " << f.errorString();; |
826 | return QString(); | 829 | return QString(); |
827 | } | 830 | } |
828 | 831 | ||