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

command-7z: Add new 7-zip(7zz and 7zzs) project support #472

Merged
merged 1 commit into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions data/packages.match
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ lzma=
lzop=
ncompress=
nomarch=
p7zip=
p7zip-full=
p7zip-rar=
7zip=
7zip-full=
7zip-rar=
rar=
rpm=
rzip=
Expand Down
35 changes: 25 additions & 10 deletions src/fr-command-7z.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,15 @@ list__process_line (char *line,
static void
fr_command_7z_begin_command (FrCommand *comm)
{
if (is_program_in_path ("7z"))
// Modern 7-Zip by the original author.
// Statically linked from a binary distribution, almost guaranteed to work.
if (is_program_in_path ("7zzs"))
fr_process_begin_command (comm->process, "7zzs");
// Dynamically linked from either binary or source distribution.
else if (is_program_in_path ("7zz"))
fr_process_begin_command (comm->process, "7zz");
// Legacy p7zip project.
else if (is_program_in_path ("7z"))
fr_process_begin_command (comm->process, "7z");
else if (is_program_in_path ("7za"))
fr_process_begin_command (comm->process, "7za");
Expand Down Expand Up @@ -333,8 +341,10 @@ fr_command_7z_add (FrCommand *comm,

if (spd_support) fr_process_add_arg (comm->process, "-spd");
fr_process_add_arg (comm->process, "-bd");
fr_process_add_arg (comm->process, "-bb1");
fr_process_add_arg (comm->process, "-y");
fr_process_add_arg (comm->process, "-l");
if (recursive)
fr_process_add_arg (comm->process, "-l");
add_password_arg (comm, comm->password, FALSE);
if ((comm->password != NULL)
&& (*comm->password != 0)
Expand Down Expand Up @@ -465,6 +475,7 @@ fr_command_7z_extract (FrCommand *comm,

if (spd_support) fr_process_add_arg (comm->process, "-spd");
fr_process_add_arg (comm->process, "-bd");
fr_process_add_arg (comm->process, "-bb1");
fr_process_add_arg (comm->process, "-y");
add_password_arg (comm, comm->password, FALSE);

Expand Down Expand Up @@ -600,24 +611,28 @@ fr_command_7z_get_capabilities (FrCommand *comm,
FrCommandCaps capabilities;

capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
if (! is_program_available ("7za", check_command) && ! is_program_available ("7zr", check_command) && ! is_program_available ("7z", check_command))
gboolean available_7zip = is_program_available ("7zz", check_command) || is_program_available ("7zzs", check_command);
if (! available_7zip\
&& ! is_program_available ("7za", check_command) \
&& ! is_program_available ("7zr", check_command) \
&& ! is_program_available ("7z", check_command))
return capabilities;

if (is_mime_type (mime_type, "application/x-7z-compressed")) {
capabilities |= FR_COMMAND_CAN_READ_WRITE | FR_COMMAND_CAN_CREATE_VOLUMES;
if (is_program_available ("7z", check_command))
if (is_program_available ("7z", check_command) || available_7zip)
capabilities |= FR_COMMAND_CAN_ENCRYPT | FR_COMMAND_CAN_ENCRYPT_HEADER;
}
else if (is_mime_type (mime_type, "application/x-7z-compressed-tar")) {
capabilities |= FR_COMMAND_CAN_READ_WRITE;
if (is_program_available ("7z", check_command))
if (is_program_available ("7z", check_command) || available_7zip)
capabilities |= FR_COMMAND_CAN_ENCRYPT | FR_COMMAND_CAN_ENCRYPT_HEADER;
}
else if (is_program_available ("7z", check_command)) {
else if (is_program_available ("7z", check_command) || available_7zip) {
if (is_mime_type (mime_type, "application/x-rar")
|| is_mime_type (mime_type, "application/x-cbr"))
{
if (! check_command || g_file_test ("/usr/lib/p7zip/Codecs/Rar29.so", G_FILE_TEST_EXISTS) || g_file_test ("/usr/lib/p7zip/Codecs/Rar.so", G_FILE_TEST_EXISTS)
if (! check_command || available_7zip || g_file_test ("/usr/lib/p7zip/Codecs/Rar29.so", G_FILE_TEST_EXISTS) || g_file_test ("/usr/lib/p7zip/Codecs/Rar.so", G_FILE_TEST_EXISTS)
|| g_file_test ("/usr/libexec/p7zip/Codecs/Rar29.so", G_FILE_TEST_EXISTS) || g_file_test ("/usr/libexec/p7zip/Codecs/Rar.so", G_FILE_TEST_EXISTS))
capabilities |= FR_COMMAND_CAN_READ;
}
Expand Down Expand Up @@ -655,11 +670,11 @@ fr_command_7z_get_packages (FrCommand *comm,
const char *mime_type)
{
if (is_mime_type (mime_type, "application/x-rar"))
return PACKAGES ("p7zip,p7zip-rar");
return PACKAGES ("7zip,7zip-rar");
else if (is_mime_type (mime_type, "application/zip") || is_mime_type (mime_type, "application/vnd.ms-cab-compressed"))
return PACKAGES ("p7zip,p7zip-full");
return PACKAGES ("7zip,7zip-full");
else
return PACKAGES ("p7zip");
return PACKAGES ("7zip");
}

static void
Expand Down
9 changes: 5 additions & 4 deletions src/fr-command-tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,8 @@ fr_command_tar_recompress (FrCommand *comm)
fr_process_add_arg (comm->process, "a");
fr_process_add_arg (comm->process, "-bd");
fr_process_add_arg (comm->process, "-y");
fr_process_add_arg (comm->process, "-l");
if (g_strcmp0 (comm_tar->compress_command, "7zzs") != 0 && g_strcmp0 (comm_tar->compress_command, "7zz") != 0)
fr_process_add_arg (comm->process, "-l");

new_name = g_strconcat (c_tar->uncomp_filename, ".7z", NULL);
fr_process_add_arg_concat (comm->process, new_name, NULL);
Expand Down Expand Up @@ -1061,7 +1062,7 @@ fr_command_tar_get_capabilities (FrCommand *comm,
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-7z-compressed-tar")) {
const char *try_command[3] = { "7za", "7zr", "7z" };
const char *try_command[5] = { "7zzs", "7zz", "7za", "7zr", "7z" };
size_t i;

for (i = 0; i < G_N_ELEMENTS (try_command); i++) {
Expand All @@ -1088,7 +1089,7 @@ fr_command_tar_set_mime_type (FrCommand *comm,
FR_COMMAND_CLASS (parent_class)->set_mime_type (comm, mime_type);

if (is_mime_type (mime_type, "application/x-7z-compressed-tar")) {
const char *try_command[3] = { "7za", "7zr", "7z" };
const char *try_command[5] = { "7zzs", "7zz", "7za", "7zr", "7z" };
size_t i;

for (i = 0; i < G_N_ELEMENTS (try_command); i++) {
Expand Down Expand Up @@ -1125,7 +1126,7 @@ fr_command_tar_get_packages (FrCommand *comm,
else if (is_mime_type (mime_type, "application/x-lzop-compressed-tar"))
return PACKAGES ("tar,lzop");
else if (is_mime_type (mime_type, "application/x-7z-compressed-tar"))
return PACKAGES ("tar,p7zip");
return PACKAGES ("tar,7zip");
else if (is_mime_type (mime_type, "application/x-zstd-compressed-tar"))
return PACKAGES ("tar,zstd");

Expand Down