Skip to content

Commit

Permalink
Ensure .owncloudsync.log has the correct encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Apr 7, 2022
1 parent 12b62cb commit 576e17d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 29 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/9571
Original file line number Diff line number Diff line change
@@ -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
72 changes: 44 additions & 28 deletions src/gui/syncrunfilelog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
2 changes: 1 addition & 1 deletion src/gui/syncrunfilelog.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SyncRunFileLog
QScopedPointer<QFile> _file;
QElapsedTimer _totalDuration;
QElapsedTimer _lapDuration;
QScopedPointer<QDebug> _out;
QScopedPointer<QTextStream> _out;
};
}

Expand Down

0 comments on commit 576e17d

Please sign in to comment.