Skip to content

Commit

Permalink
Log percent-encoded URL/filename
Browse files Browse the repository at this point in the history
This can be used to debug Unicode normalization/encoding issues.
  • Loading branch information
erikjv committed Nov 29, 2024
1 parent 83d7be7 commit b9b5651
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,15 @@ void ProcessDirectoryJob::processFile(const PathTuple &path,
const LocalInfo &localEntry, const RemoteInfo &serverEntry,
const SyncJournalFileRecord &dbEntry)
{
// The percent-encoded file name as it would be passed in an HTTP request. This can be used to
// debug Unicode encoding/normalization issues.
auto encodedFileName = QUrl::fromLocalFile(path._original).toEncoded().sliced(std::string_view("file:").length());
const char *hasServer = serverEntry.isValid() ? "true" : _queryServer == ParentNotChanged ? "db" : "false";
const char *hasLocal = localEntry.isValid() ? "true" : _queryLocal == ParentNotChanged ? "db" : "false";

// The code below is formatted like this ON PURPOSE: each field is db/local/server, one field
// per (source code) line, so it's easy to understand.
// clang-format off
qCInfo(lcDisco).nospace() << "Processing " << path._original
<< " | valid: " << dbEntry.isValid() << "/" << hasLocal << "/" << hasServer
<< " | mtime: " << dbEntry._modtime << "/" << localEntry.modtime << "/" << serverEntry.modtime
Expand All @@ -319,7 +326,9 @@ void ProcessDirectoryJob::processFile(const PathTuple &path,
<< " | perm: " << dbEntry._remotePerm << "//" << serverEntry.remotePerm
<< " | fileid: " << dbEntry._fileId << "//" << serverEntry.fileId
<< " | inode: " << dbEntry._inode << "/" << localEntry.inode << "/"
<< " | type: " << dbEntry._type << "/" << localEntry.type << "/" << (serverEntry.isDirectory ? ItemTypeDirectory : ItemTypeFile);
<< " | type: " << dbEntry._type << "/" << localEntry.type << "/" << (serverEntry.isDirectory ? ItemTypeDirectory : ItemTypeFile)
<< " (" << encodedFileName << ")";
// clang-format on

if (_discoveryData->isRenamed(path._original)) {
qCDebug(lcDisco) << "Ignoring renamed";
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/httplogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool isTextBody(const QString &s)
struct HttpContext
{
HttpContext(const QNetworkRequest &request)
: originalUrl(request.url().toString())
: originalUrl(QString::fromUtf8(request.url().toEncoded())) // Encoded URL as it is passed "over the wire"
, lastUrl(request.url())
, id(QString::fromUtf8(request.rawHeader(QByteArrayLiteral("X-Request-ID"))))
{
Expand Down

0 comments on commit b9b5651

Please sign in to comment.