From 576e17d474209fa14df5f7e7d27b20f13ed31de3 Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Thu, 7 Apr 2022 13:37:03 +0200 Subject: [PATCH 1/3] Ensure .owncloudsync.log has the correct encoding --- changelog/unreleased/9571 | 5 +++ src/gui/syncrunfilelog.cpp | 72 +++++++++++++++++++++++--------------- src/gui/syncrunfilelog.h | 2 +- 3 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 changelog/unreleased/9571 diff --git a/changelog/unreleased/9571 b/changelog/unreleased/9571 new file mode 100644 index 00000000000..cf595dd4e3d --- /dev/null +++ b/changelog/unreleased/9571 @@ -0,0 +1,5 @@ +Bugfix: Use UTF-8 for .owncloudsync.log + +We fixed a bug where unicode file names where not correctly displayed in .owncloudsync.log. + +https://github.com/owncloud/client/pull/9571 diff --git a/src/gui/syncrunfilelog.cpp b/src/gui/syncrunfilelog.cpp index 496c8d892dd..e369f847384 100644 --- a/src/gui/syncrunfilelog.cpp +++ b/src/gui/syncrunfilelog.cpp @@ -51,15 +51,19 @@ void SyncRunFileLog::start(const QString &folderPath) QFile::rename(filename, newFilename); } _file.reset(new QFile(filename)); - _file->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text); - _out.reset(new QDebug(_file.data())); - _out->noquote(); + + + // we use a text stream to ensure the encoding is ok + // when outputiing info we use QDebug to ensure we can use the debug operatos + _out.reset(new QTextStream(_file.data())); + _out->setCodec("UTF-8"); if (!exists) { // We are creating a new file, add the note. - *_out << "# timestamp | duration | file | instruction | dir | modtime | etag | " + *_out << "Log for:" << folderPath << endl + << "# timestamp | duration | file | instruction | dir | modtime | etag | " "size | fileId | status | errorString | http result code | " "other size | other modtime | X-Request-ID" << endl; @@ -81,38 +85,50 @@ void SyncRunFileLog::logItem(const SyncFileItem &item) return; } const QChar L = QLatin1Char('|'); - *_out << dateTimeStr(QDateTime::fromString(QString::fromUtf8(item._responseTimeStamp), Qt::RFC2822Date)) << L - << ((item._instruction != CSYNC_INSTRUCTION_RENAME) ? item.destination() : item._file + QStringLiteral(" -> ") + item._renameTarget) << L - << item._instruction << L - << item._direction << L - << L - << item._modtime << L - << item._etag << L - << item._size << L - << item._fileId << L - << item._status << L - << item._errorString << L - << item._httpErrorCode << L - << item._previousSize << L - << item._previousModtime << L - << item._requestId << L - << endl; + QString tmp; + { + QDebug(&tmp).noquote() << dateTimeStr(QDateTime::fromString(QString::fromUtf8(item._responseTimeStamp), Qt::RFC2822Date)) << L + << ((item._instruction != CSYNC_INSTRUCTION_RENAME) ? item.destination() : item._file + QStringLiteral(" -> ") + item._renameTarget) << L + << item._instruction << L + << item._direction << L + << L + << item._modtime << L + << item._etag << L + << item._size << L + << item._fileId << L + << item._status << L + << item._errorString << L + << item._httpErrorCode << L + << item._previousSize << L + << item._previousModtime << L + << item._requestId << L + << endl; + } + *_out << tmp; } void SyncRunFileLog::logLap(const QString &name) { - *_out << "#=#=#=#=#" << name << dateTimeStr() - << "(last step:" << _lapDuration.restart() << "msec" - << ", total:" << _totalDuration.elapsed() << "msec)" - << endl; + QString tmp; + { + QDebug(&tmp).noquote() << "#=#=#=#=#" << name << dateTimeStr() + << "(last step:" << _lapDuration.restart() << "msec" + << ", total:" << _totalDuration.elapsed() << "msec)" + << endl; + } + *_out << tmp; } void SyncRunFileLog::finish() { - *_out << "#=#=#=# Syncrun finished" << dateTimeStr() - << "(last step:" << _lapDuration.elapsed() << "msec" - << ", total:" << _totalDuration.elapsed() << "msec)" - << endl; + QString tmp; + { + QDebug(&tmp).noquote() << "#=#=#=# Syncrun finished" << dateTimeStr() + << "(last step:" << _lapDuration.elapsed() << "msec" + << ", total:" << _totalDuration.elapsed() << "msec)" + << endl; + } + *_out << tmp; _file->close(); } } diff --git a/src/gui/syncrunfilelog.h b/src/gui/syncrunfilelog.h index 8a5fb0e1d67..d4496a89171 100644 --- a/src/gui/syncrunfilelog.h +++ b/src/gui/syncrunfilelog.h @@ -43,7 +43,7 @@ class SyncRunFileLog QScopedPointer _file; QElapsedTimer _totalDuration; QElapsedTimer _lapDuration; - QScopedPointer _out; + QScopedPointer _out; }; } From c5bad6104e32d244c22c01b541d715c95fbb39e1 Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Thu, 7 Apr 2022 16:45:15 +0200 Subject: [PATCH 2/3] Update changelog/unreleased/9571 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fabian Müller <80399010+fmoc@users.noreply.github.com> --- changelog/unreleased/9571 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/unreleased/9571 b/changelog/unreleased/9571 index cf595dd4e3d..d39902b8343 100644 --- a/changelog/unreleased/9571 +++ b/changelog/unreleased/9571 @@ -1,5 +1,5 @@ Bugfix: Use UTF-8 for .owncloudsync.log -We fixed a bug where unicode file names where not correctly displayed in .owncloudsync.log. +We fixed a bug where unicode file names were not correctly displayed in .owncloudsync.log. https://github.com/owncloud/client/pull/9571 From 0dddd4d4855b3cba76cf3662e6ac573601c49f1a Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Thu, 7 Apr 2022 16:45:21 +0200 Subject: [PATCH 3/3] Update src/gui/syncrunfilelog.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Fabian Müller <80399010+fmoc@users.noreply.github.com> --- src/gui/syncrunfilelog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/syncrunfilelog.cpp b/src/gui/syncrunfilelog.cpp index e369f847384..220c46e498e 100644 --- a/src/gui/syncrunfilelog.cpp +++ b/src/gui/syncrunfilelog.cpp @@ -55,7 +55,7 @@ void SyncRunFileLog::start(const QString &folderPath) // we use a text stream to ensure the encoding is ok - // when outputiing info we use QDebug to ensure we can use the debug operatos + // when outputting info, we use QDebug to ensure we can use the debug operators _out.reset(new QTextStream(_file.data())); _out->setCodec("UTF-8");