Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure .owncloudsync.log has the correct encoding #9571

Merged
merged 3 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
TheOneRing marked this conversation as resolved.
Show resolved Hide resolved

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
TheOneRing marked this conversation as resolved.
Show resolved Hide resolved
_out.reset(new QTextStream(_file.data()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By changing this from QDebug to QTextStream, don't you loose the formatting of standard types (QDateTime) that QDebug has? QDebug also takes an IODevice in the constructor which you could set an encoding before passing it on to QDebug.

For me this is a risky and not not really needed refactoring tbh. We really should not accidentially change any formatting of the file as people might parse it etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats why I still use QDebug in the 3 functions.
I only switched to QDebug 6 month ago, but utf8 never worked on Windows.

Copy link
Contributor

@fmoc fmoc Apr 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QIODevice and subclasses do not provide any kind of encoding feature, only QTextStream provides this. However, a QTextStream is not a QIODevice, and cannot it be wrapped by one (actually, it works the other way round, you can open a QTextStream for a QIODevice).

So, yes, would be nice to have, but it's not possible in Qt at the moment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, yes. Sorry.

_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;
fmoc marked this conversation as resolved.
Show resolved Hide resolved
{
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