Skip to content

Commit

Permalink
Add xz, zstd and plain tar support
Browse files Browse the repository at this point in the history
  • Loading branch information
iliajie committed Sep 24, 2023
1 parent 09eed81 commit 7974b13
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
30 changes: 24 additions & 6 deletions extensions/file-manager/compress.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ if (!$in{'arch'}) {

my %errors;
my $command;
my $extension;

my @entries_list = get_entries_list();
my $delete = $in{'arcmove'} ? 1 : 0;
Expand All @@ -28,22 +27,41 @@ my $status;
my $safe_mode = $in{'overwrite_efiles'} ne 'true';
my $follow_symlinks = $in{'follow_symlinks'} eq 'true';

if ($in{'method'} eq 'tar' || $in{'method'} eq 'zip') {
if ($in{'method'} =~ /tar/ || $in{'method'} eq 'zip') {
my $list = transname();
open my $fh, ">", $list or die $!;
print $fh "$_\n" for @entries_list;
close $fh;

if ($in{'method'} eq 'tar') {
if ($in{'method'} =~ /tar/) {
if (!has_command('tar')) {
$errors{ $text{'theme_xhred_global_error'} } = text('theme_xhred_global_no_such_command', 'tar');
}
if (!has_command('xz') && $in{'method'} eq 'xz-tar') {
$errors{ $text{'theme_xhred_global_error'} } = text('theme_xhred_global_no_such_command', 'xz');
}
if (!has_command('zstd') && $in{'method'} eq 'zstd-tar') {
$errors{ $text{'theme_xhred_global_error'} } = text('theme_xhred_global_no_such_command', 'zstd');
}

my $tarcmd = 'tar cz'; # gzip is default
my $extension = 'tar.gz';
if ($in{'method'} eq 'xz-tar') {
$tarcmd = 'tar cJ'; # xz
$extension = 'tar.xz';
} elsif ($in{'method'} eq 'zstd-tar') {
$tarcmd = 'ZSTD_CLEVEL=19 tar --zstd -c'; # zstd
$extension = 'zst';
} elsif ($in{'method'} eq 'plain-tar') {
$tarcmd = 'tar c'; # tar, with no compression
$extension = 'tar';
}

my $file = "$cwd/$in{'arch'}.tar.gz";
my $file = "$cwd/$in{'arch'}.$extension";
if (-e $file && $safe_mode) {
my $__ = 1;
for (;;) {
my $new_file = "$cwd/$in{'arch'}(" . $__++ . ").tar.gz";
my $new_file = "$cwd/$in{'arch'}(" . $__++ . ").$extension";
if (!-e $new_file) {
$file = $new_file;
last;
Expand All @@ -53,7 +71,7 @@ if ($in{'method'} eq 'tar' || $in{'method'} eq 'zip') {
my $fileq = quotemeta($file);
my $gnu_tar_param = get_tar_verbatim();
my $follow_symlinks = $follow_symlinks ? 'h' : '';
$command = "tar czf$follow_symlinks " . $fileq . " -C " . quotemeta($cwd) . "$gnu_tar_param -T " . $list;
$command = "${tarcmd}f$follow_symlinks " . $fileq . " -C " . quotemeta($cwd) . "$gnu_tar_param -T " . $list;
$status = system($command);

if ($encrypt && $key_id) {
Expand Down
2 changes: 1 addition & 1 deletion extensions/file-manager/extract.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ foreach my $name (@entries_list) {
}

my $archive_type = mimetype($cwd . '/' . $name);
if ($archive_type =~ /x-tar/ || $archive_type =~ /-compressed-tar/) {
if ($archive_type =~ /x-tar/ || $archive_type =~ /-compressed-tar/ || $archive_type =~ /zstd/) {
my $tar_cmd = has_command('tar');
if (!$tar_cmd) {
$errors{ $text{'theme_xhred_global_error'} } = text('theme_xhred_global_no_such_command', 'tar');
Expand Down
1 change: 1 addition & 0 deletions extensions/file-manager/file-manager-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ sub print_content
$type_archive =~ /application-x-deb|debian\.binary-package/ ||
$type_archive =~ /application-x-raw-disk-image/ ||
$type_archive =~ /application-x-cd-image/ ||
$type_archive =~ /zstd/ ||
$type_archive =~ /-compressed-tar/ ||
$type_archive =~ /-x-tar/ ||
$type_archive =~ /-x-bzip/ ||
Expand Down

0 comments on commit 7974b13

Please sign in to comment.