Fix incorrect logger output for non-latin strings.
authorallexzander <blackslayer4@gmail.com>
Thu, 11 Feb 2021 21:21:12 +0000 (23:21 +0200)
committerallexzander <blackslayer4@gmail.com>
Tue, 16 Feb 2021 07:30:08 +0000 (09:30 +0200)
Signed-off-by: allexzander <blackslayer4@gmail.com>
src/common/ownsql.h
src/common/syncjournaldb.cpp
src/common/syncjournalfilerecord.h
src/libsync/discovery.cpp
src/libsync/logger.cpp
src/libsync/syncengine.cpp
src/libsync/syncfileitem.cpp
test/syncenginetestutils.cpp

index 894bef85bd780f86a1f6d734e4084e7fe7d473b1..300bdc482aabbbebe18168f7b5a8ee120f8e2603 100644 (file)
@@ -152,6 +152,12 @@ public:
         bindValueInternal(pos, value);
     }
 
+    void bindValue(int pos, const QByteArray &value)
+    {
+        qCDebug(lcSql) << "SQL bind" << pos << QString::fromUtf8(value);
+        bindValueInternal(pos, value);
+    }
+
     const QByteArray &lastQuery() const;
     int numRowsAffected();
     void reset_and_clear_bindings();
index 8e2a6d81a3f9a43cfae9b79342400392cbb328b7..ff6aafa3e26e0bbbb45424939a12587615cab339 100644 (file)
@@ -909,11 +909,11 @@ bool SyncJournalDb::setFileRecord(const SyncJournalFileRecord &_record)
         }
     }
 
-    qCInfo(lcDb) << "Updating file record for path:" << record._path << "inode:" << record._inode
+    qCInfo(lcDb) << "Updating file record for path:" << record.path() << "inode:" << record._inode
                  << "modtime:" << record._modtime << "type:" << record._type
                  << "etag:" << record._etag << "fileId:" << record._fileId << "remotePerm:" << record._remotePerm.toString()
                  << "fileSize:" << record._fileSize << "checksum:" << record._checksumHeader
-                 << "e2eMangledName:" << record._e2eMangledName << "isE2eEncrypted:" << record._isE2eEncrypted;
+                 << "e2eMangledName:" << record.e2eMangledName() << "isE2eEncrypted:" << record._isE2eEncrypted;
 
     qlonglong phash = getPHash(record._path);
     if (checkConnect()) {
@@ -1241,7 +1241,7 @@ bool SyncJournalDb::listFilesInPath(const QByteArray& path,
         SyncJournalFileRecord rec;
         fillFileRecordFromGetQuery(rec, _listFilesInPathQuery);
         if (!rec._path.startsWith(path) || rec._path.indexOf("/", path.size() + 1) > 0) {
-            qWarning(lcDb) << "hash collision" << path << rec._path;
+            qWarning(lcDb) << "hash collision" << path << rec.path();
             continue;
         }
         rowCallback(rec);
index 3a8643fe845af145b66ace83249bd63c4bc085fc..b47f98e5b5d7348ab3dde2fff652d18c0203bad6 100644 (file)
@@ -55,6 +55,8 @@ public:
     bool isDirectory() const { return _type == ItemTypeDirectory; }
     bool isFile() const { return _type == ItemTypeFile || _type == ItemTypeVirtualFileDehydration; }
     bool isVirtualFile() const { return _type == ItemTypeVirtualFile || _type == ItemTypeVirtualFileDownload; }
+    QString path() const { return QString::fromUtf8(_path); }
+    QString e2eMangledName() const { return QString::fromUtf8(_e2eMangledName); }
 
     QByteArray _path;
     quint64 _inode = 0;
index 6c025460005f9eae487729846e2092c7e6f41ce8..95cb7bf348de10b4e50c231af4e0c411af51f02f 100644 (file)
@@ -319,7 +319,7 @@ void ProcessDirectoryJob::processFile(PathTuple path,
                               << " | inode: " << dbEntry._inode << "/" << localEntry.inode << "/"
                               << " | type: " << dbEntry._type << "/" << localEntry.type << "/" << (serverEntry.isDirectory ? ItemTypeDirectory : ItemTypeFile)
                               << " | e2ee: " << dbEntry._isE2eEncrypted << "/" << serverEntry.isE2eEncrypted
-                              << " | e2eeMangledName: " << dbEntry._e2eMangledName << "/" << serverEntry.e2eMangledName;
+                              << " | e2eeMangledName: " << dbEntry.e2eMangledName() << "/" << serverEntry.e2eMangledName;
 
     if (_discoveryData->isRenamed(path._original)) {
         qCDebug(lcDisco) << "Ignoring renamed";
@@ -564,7 +564,7 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
         }
 
         // Now we know there is a sane rename candidate.
-        QString originalPath = QString::fromUtf8(base._path);
+        QString originalPath = base.path();
 
         if (_discoveryData->isRenamed(originalPath)) {
             qCInfo(lcDisco, "folder already has a rename entry, skipping");
@@ -896,7 +896,7 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
         dbError();
         return;
     }
-    const auto originalPath = QString::fromUtf8(base._path);
+    const auto originalPath = base.path();
 
     // Function to gradually check conditions for accepting a move-candidate
     auto moveCheck = [&]() {
index 1b7b8791a6ab5b8a60f4602dfa2935283482210f..9a45e6059d1e7b4bff9d91877f7012e66a125ab8 100644 (file)
@@ -19,6 +19,7 @@
 #include <QDir>
 #include <QStringList>
 #include <QtGlobal>
+#include <QTextCodec>
 #include <qmetaobject.h>
 
 #include <iostream>
@@ -198,6 +199,7 @@ void Logger::setLogFile(const QString &name)
     }
 
     _logstream.reset(new QTextStream(&_logFile));
+    _logstream->setCodec(QTextCodec::codecForName("UTF-8"));
 }
 
 void Logger::setLogExpire(int expire)
index 9893058b7db5af546f5bdbb58bccec6233fc94dd..f6a23261a2a481d3ccec0b1b53dc93ae6dda2dd8 100644 (file)
@@ -989,14 +989,14 @@ void SyncEngine::wipeVirtualFiles(const QString &localPath, SyncJournalDb &journ
         if (rec._type != ItemTypeVirtualFile && rec._type != ItemTypeVirtualFileDownload)
             return;
 
-        qCDebug(lcEngine) << "Removing db record for" << rec._path;
+        qCDebug(lcEngine) << "Removing db record for" << rec.path();
         journal.deleteFileRecord(rec._path);
 
         // If the local file is a dehydrated placeholder, wipe it too.
         // Otherwise leave it to allow the next sync to have a new-new conflict.
         QString localFile = localPath + rec._path;
         if (QFile::exists(localFile) && vfs.isDehydratedPlaceholder(localFile)) {
-            qCDebug(lcEngine) << "Removing local dehydrated placeholder" << rec._path;
+            qCDebug(lcEngine) << "Removing local dehydrated placeholder" << rec.path();
             QFile::remove(localFile);
         }
     });
index de33eb70f7dff61ed491b889d6f11f7bcdefba3c..cc7afe0f0e8114d6e97d7e42bae189cf980e5b3d 100644 (file)
@@ -63,7 +63,7 @@ SyncJournalFileRecord SyncFileItem::toSyncJournalFileRecordWithInode(const QStri
 SyncFileItemPtr SyncFileItem::fromSyncJournalFileRecord(const SyncJournalFileRecord &rec)
 {
     auto item = SyncFileItemPtr::create();
-    item->_file = QString::fromUtf8(rec._path);
+    item->_file = rec.path();
     item->_inode = rec._inode;
     item->_modtime = rec._modtime;
     item->_type = rec._type;
@@ -73,7 +73,7 @@ SyncFileItemPtr SyncFileItem::fromSyncJournalFileRecord(const SyncJournalFileRec
     item->_remotePerm = rec._remotePerm;
     item->_serverHasIgnoredFiles = rec._serverHasIgnoredFiles;
     item->_checksumHeader = rec._checksumHeader;
-    item->_encryptedFileName = QString::fromUtf8(rec._e2eMangledName);
+    item->_encryptedFileName = rec.e2eMangledName();
     item->_isEncrypted = rec._isE2eEncrypted;
     return item;
 }
index aba75d6c4bf7c86c23b67765fdb96fe5c123b9cb..88d276e494e28c2ab71f4f47b005493be06a6a44 100644 (file)
@@ -995,7 +995,7 @@ FileInfo FakeFolder::dbState() const
 {
     FileInfo result;
     _journalDb->getFilesBelowPath("", [&](const OCC::SyncJournalFileRecord &record) {
-        auto components = PathComponents(QString::fromUtf8(record._path));
+        auto components = PathComponents(record.path());
         auto &parentDir = findOrCreateDirs(result, components.parentDirComponents());
         auto name = components.fileName();
         auto &item = parentDir.children[name];