Skip to content

Draft: cli7zplugin: attempt to fix opening 7z archives with omitted attributes (`-mtr=off` flag)

Hanabishi Recca requested to merge hanabishi/ark:mtroff-fix into master

This MR attempts to fix https://bugs.kde.org/show_bug.cgi?id=476196


Currently Ark fails to parse a 7z archive if it was created with attributes omitted (-mtr=off flag).

This is because Ark relies on D attribute to detect directories inside 7z archives. https://invent.kde.org/utilities/ark/-/blob/8c7e0a2117fc6db538b3df33b19e9b910f07c160/plugins/cli7zplugin/cliplugin.cpp#L259

Usually archive records look like this:

Path = test
Size = 0
Packed Size = 0
Modified = 2023-10-28 12:52:18.4874650
Attributes = D drwxr-xr-x
CRC =
Encrypted = -
Method =
Block =

But when '-mtr=off' flag is used during archive creation, all attribuites are omitted:

Path = test
Size = 0
Packed Size = 0
Modified = 2023-10-28 12:52:18.4874650
CRC =
Encrypted = -
Method =
Block =

So Ark fails to detect it as a directory. Resulting archive opens like a total mess.

Or using debug Ark build, it crashes with failed assertion.

ASSERT: "isDir()" in file /ark/kerfuffle/archiveentry.cpp, line 90
[1]    18771 IOT instruction (core dumped)  ark /test.7z

This MR generally solves the issue, but there is still an unresolved problem: in such archives empty files will be shown as directories.
We can't really do anything with it, as I already stated in the bug report:

Path = test
Size = 0
Packed Size = 0
Modified = 2023-10-28 13:10:47.8804270
CRC =
Encrypted = -
Method =
Block =
Path = test/test
Size = 0
Packed Size = 0
Modified = 2023-10-28 13:10:49.8933970
CRC =
Encrypted = -
Method =
Block =

The first record is a directory, the second is an empty file.
Without attributes, there is no way to distinguish them via CLI.

Edited by Hanabishi Recca

Merge request reports