[WIP/RFC] [kioslave/file] Add a codec for legacy filenames
Needs ReviewPublic

Authored by cfeck on Jan 10 2019, 5:40 PM.


Group Reviewers

[WIP/RFC] Please let me know if what I propose is sane

UNIX filenames can contain any bytes (except \0 and /). Qt's QFile::decodeName() calls QString::fromLocal8Bit(), assuming that all filesystems use the system's locale encoding. For filenames that have been created with a different encoding, and have not yet been converted (e.g. using convmv), this creates non-reversible U+FFFD (REPLACEMENT CHARACTER) code points in the filenames.

For example, some old-style archives might not contain any information about the encoding of the filenames, and even today archivers extract them without trying to convert to the locale's encoding.

While full support for those filenames is not needed, Dolphin should at least be able to delete, rename, and move those files. Since all actual (local) file handling is done inside the file kioslave, patching Dolphin will not help.

This code is a near verbatim copy of the code we had in kdelibs, written by Szókovács Róbert. Only minor adaptions to Qt5 were done. It decodes invalid bytes as U+10FExx from Plane 16 (Supplementary Private Use Area-B) to be able to encode them later.

Dolphin could detect filenames with those characters, and either mark them (by color or overlay icon), or even automatically offer to rename them.

CCBUG: 204768
CCBUG: 165044

Test Plan

touch "/tmp/test-"$'\377'".txt"
dolphin /tmp

Copying and deleting a test file worked with this code, failed without.

Diff Detail

R241 KIO
Lint Skipped
Unit Tests Skipped
cfeck created this revision.Jan 10 2019, 5:40 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptJan 10 2019, 5:40 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
cfeck requested review of this revision.Jan 10 2019, 5:40 PM
ngraham added a subscriber: ngraham.

I tried with my script that tried to reproduce that "kio skips files" issue
and then letting it run.
Unfortunately, I get "The file protocol died unexpectedly

cfeck updated this revision to Diff 49684.Jan 17 2019, 12:45 AM

Fix worst case estimate. We need up to two UTF-16 code units for each byte.

Awesome! For what I can input, base file operations work. I can copy, delete, rename files, and testing, and diffing the trees with my kiocopy test script, it copies them perfectly. However, for example, some of the files I cannot open with kate

cfeck added a comment.Jan 17 2019, 4:11 AM

It's possible that Kate doesn't use KIO for local files, but falls back to QFile. It _would_ be possible somehow (e.g. via the QPA plugins) to inject the hack into all Qt applications, but I suggest to improve Dolphin in a way that it shows an error message or even a rename dialog when trying to open or execute such a file.

cfeck added a comment.Jan 17 2019, 4:12 AM

Thanks for testing, btw.

Wow, it's nice that this is fixable, I thought it wasn't.

I can't really review the code itself though, too clueless about utf8 details. Thiago might be able to review this.