Compare commits
8 Commits
fb37d091d6
...
21fe1bfd33
Author | SHA1 | Date | |
---|---|---|---|
21fe1bfd33 | |||
fd0c953014 | |||
ce9a1fde0e | |||
b562a07251 | |||
bded568aa0 | |||
9605a118df | |||
effc9b8657 | |||
67dca3926a |
5
Build.PL
5
Build.PL
@ -61,8 +61,9 @@ my $build = Module::Build->new(
|
|||||||
},
|
},
|
||||||
recommends => {
|
recommends => {
|
||||||
"File::MMagic" => 0,
|
"File::MMagic" => 0,
|
||||||
"Compress::Zlib" => 0,
|
"IO::Compress::Gzip" => 0,
|
||||||
"Compress::Bzip2" => 2,
|
"IO::Compress::Bzip2" => 0,
|
||||||
|
"IO::Compress::Xz" => 0,
|
||||||
"Term::ReadKey" => 0,
|
"Term::ReadKey" => 0,
|
||||||
},
|
},
|
||||||
build_requires => {
|
build_requires => {
|
||||||
|
7
Changes
7
Changes
@ -1,5 +1,12 @@
|
|||||||
reslog change log
|
reslog change log
|
||||||
|
|
||||||
|
2022-03-19 version 3.18
|
||||||
|
1. Added support for the xz compression.
|
||||||
|
2. Replaced Compress::Zlib with IO::Compress::Gzip and
|
||||||
|
IO::Uncompress::Gunzip.
|
||||||
|
3. Replaced Compress::Bzip2 with IO::Compress::Bzip2 and
|
||||||
|
IO::Uncompress::Bunzip2.
|
||||||
|
|
||||||
2020-02-06 version 3.17
|
2020-02-06 version 3.17
|
||||||
1. Replaced the messy GNU-styled, multi-lingual documents with a
|
1. Replaced the messy GNU-styled, multi-lingual documents with a
|
||||||
single Markdown README.md.
|
single Markdown README.md.
|
||||||
|
@ -52,8 +52,9 @@ EOT
|
|||||||
our (%OPT_PREREQ);
|
our (%OPT_PREREQ);
|
||||||
%OPT_PREREQ = (
|
%OPT_PREREQ = (
|
||||||
"File::MMagic" => 0,
|
"File::MMagic" => 0,
|
||||||
"Compress::Zlib" => 0,
|
"IO::Compress::Gzip" => 0,
|
||||||
"Compress::Bzip2" => 2,
|
"IO::Compress::Bzip2" => 0,
|
||||||
|
"IO::Compress::Xz" => 0,
|
||||||
"Term::ReadKey" => 0,
|
"Term::ReadKey" => 0,
|
||||||
);
|
);
|
||||||
delete $OPT_PREREQ{$_}
|
delete $OPT_PREREQ{$_}
|
||||||
|
113
README.md
113
README.md
@ -40,10 +40,10 @@ Caution
|
|||||||
* I suggest that you install [File::MMagic] instead of counting on the
|
* I suggest that you install [File::MMagic] instead of counting on the
|
||||||
`file` executable. The internal magic file of File::MMagic works
|
`file` executable. The internal magic file of File::MMagic works
|
||||||
better than the `file` executable. `reslog` treats everything not
|
better than the `file` executable. `reslog` treats everything not
|
||||||
gzip nor bzip2 compressed as plain text. When a compressed log file
|
gzip, bzip2, nor xz compressed as plain text. When a compressed log
|
||||||
is wrongly recognized as an image, `reslog` treats it as plain text,
|
file is wrongly recognized as an image, `reslog` treats it as plain
|
||||||
reads directly from it, and fails. This does not hurt the source
|
text, reads directly from it, and fails. This does not hurt the
|
||||||
log files, but is still annoying.
|
source log files, but is still annoying.
|
||||||
|
|
||||||
[File::MMagic]: https://metacpan.org/release/File-MMagic
|
[File::MMagic]: https://metacpan.org/release/File-MMagic
|
||||||
|
|
||||||
@ -97,22 +97,23 @@ System Requirement
|
|||||||
the [GnuWin32] home page. Be sure to save it as `file.exe`
|
the [GnuWin32] home page. Be sure to save it as `file.exe`
|
||||||
somewhere in your `PATH`.
|
somewhere in your `PATH`.
|
||||||
|
|
||||||
* [Compress::Zlib]
|
* [IO::Compress::Gzip] and [IO::Uncompress::Gunzip]
|
||||||
|
|
||||||
This is used to support reading/writing the gzip compressed
|
They are used to support reading/writing the gzip compressed
|
||||||
files. It is only needed when gzip compressed files are
|
files. It is only needed when gzip compressed files are
|
||||||
encountered. If it is not available, `arclog` tries the `gzip`
|
encountered. If they are not available, `arclog` tries the
|
||||||
executable instead. If that is not available, too, `arclog`
|
`gzip` executable instead. If that is not available, too,
|
||||||
fails. You should not worry about Compress::Zlib since it comes
|
`arclog` fails. You should not worry about IO::Compress::Gzip
|
||||||
with Perl since version 5.9.3. If not, it is contained in the
|
since it comes with Perl since version 5.9.3. If not, it is
|
||||||
[IO-Compress] distribution. You can download and install it from
|
contained in the [IO-Compress] distribution. You can download
|
||||||
the CPAN archive, or install it with the CPAN shell:
|
and install it from the CPAN archive, or install it with the
|
||||||
|
CPAN shell:
|
||||||
|
|
||||||
cpan Compress::Zlib
|
cpan IO::Compress::Gzip
|
||||||
|
|
||||||
or with the CPANPLUS shell:
|
or with the CPANPLUS shell:
|
||||||
|
|
||||||
cpanp i Compress::Zlib
|
cpanp i IO::Compress::Gzip
|
||||||
|
|
||||||
For Debian/Ubuntu:
|
For Debian/Ubuntu:
|
||||||
|
|
||||||
@ -134,43 +135,80 @@ System Requirement
|
|||||||
[the gzip website]. Be sure to save it as `gzip.exe` somewhere
|
[the gzip website]. Be sure to save it as `gzip.exe` somewhere
|
||||||
in your `PATH`.
|
in your `PATH`.
|
||||||
|
|
||||||
* [Compress::Bzip2] version 2 or above.
|
* [IO::Compress::Bzip2] and [IO::Uncompress::Bunzip2]
|
||||||
|
|
||||||
This is used to support reading/writing the bzip2 compressed
|
They are used to support reading/writing the bzip2 compressed
|
||||||
files. It is only needed when bzip2 compressed files are
|
files. They are only needed when bzip2 compressed files are
|
||||||
encountered. If it is not available, `reslog` tries the `bzip2`
|
encountered. If they are not available, `arclog` tries the
|
||||||
executable instead. If that is not available, too, `reslog`
|
`bzip2` executable instead. If that is not available, too,
|
||||||
fails. Notice that older versions before 2 does not work, since
|
`arclog` fails. You should not worry about IO::Compress::Bzip2
|
||||||
the file I/O compression was not implemented yet. You can
|
since it comes with Perl since version 5.10.1. If not, it is
|
||||||
download and install Compress::Bzip2 from the CPAN archive, or
|
contained in the [IO-Compress] distribution. You can download
|
||||||
install it with the CPAN shell:
|
and install it from the CPAN archive, or install it with the
|
||||||
|
CPAN shell:
|
||||||
|
|
||||||
cpan Compress::Bzip2
|
cpan IO::Compress::Bzip2
|
||||||
|
|
||||||
or with the CPANPLUS shell:
|
or with the CPANPLUS shell:
|
||||||
|
|
||||||
cpanp i Compress::Bzip2
|
cpanp i IO::Compress::Bzip2
|
||||||
|
|
||||||
For Debian/Ubuntu:
|
For Debian/Ubuntu:
|
||||||
|
|
||||||
sudo apt install libcompress-bzip2-perl
|
sudo apt install libio-compress-perl
|
||||||
|
|
||||||
For Red Hat/Fedora/CentOS:
|
For Red Hat/Fedora/CentOS:
|
||||||
|
|
||||||
sudo yum install perl-Compress-Bzip2
|
sudo yum install perl-IO-Compress
|
||||||
|
|
||||||
For FreeBSD:
|
For FreeBSD:
|
||||||
|
|
||||||
ports install p5-Compress-Bzip2
|
ports install p5-IO-Compress
|
||||||
|
|
||||||
For ActivePerl:
|
For ActivePerl:
|
||||||
|
|
||||||
ppm install Compress-Bzip2
|
ppm install IO-Compress
|
||||||
|
|
||||||
The alternative `bzip2.exe` for MS-Windows can be obtained from
|
The alternative `bzip2.exe` for MS-Windows can be obtained from
|
||||||
[the bzip2 website]. Be sure to save it as `bzip2.exe` somewhere
|
[the bzip2 website]. Be sure to save it as `bzip2.exe` somewhere
|
||||||
in your `PATH`.
|
in your `PATH`.
|
||||||
|
|
||||||
|
* [IO::Compress::Xz] and [IO::Uncompress::UnXz]
|
||||||
|
|
||||||
|
They are used to support reading/writing the xz compressed
|
||||||
|
files. It is only needed when xz compressed files are
|
||||||
|
encountered. If it is not available, `arclog` tries the `xz`
|
||||||
|
executable instead. If that is not available, too, `arclog`
|
||||||
|
fails. They are contained in the [IO-Compress-Lzma] distribution.
|
||||||
|
You can download and install it from the CPAN archive, or install
|
||||||
|
them with the CPAN shell:
|
||||||
|
|
||||||
|
cpan IO::Compress::Xz
|
||||||
|
|
||||||
|
or with the CPANPLUS shell:
|
||||||
|
|
||||||
|
cpanp i IO::Compress::Xz
|
||||||
|
|
||||||
|
For Debian/Ubuntu:
|
||||||
|
|
||||||
|
sudo apt install libio-compress-lzma-perl
|
||||||
|
|
||||||
|
For Red Hat/Fedora/CentOS:
|
||||||
|
|
||||||
|
sudo yum install perl-IO-Compress-Lzma
|
||||||
|
|
||||||
|
For FreeBSD:
|
||||||
|
|
||||||
|
ports install p5-IO-Compress-Lzma
|
||||||
|
|
||||||
|
For ActivePerl:
|
||||||
|
|
||||||
|
ppm install IO-Compress-Lzma
|
||||||
|
|
||||||
|
The alternative `xz.exe` for MS-Windows can be obtained from
|
||||||
|
[the XZ Utils website]. Be sure to save it as `xz.exe`
|
||||||
|
somewhere in your `PATH`.
|
||||||
|
|
||||||
* [Term::ReadKey]
|
* [Term::ReadKey]
|
||||||
|
|
||||||
This is used to display the progress bar. The progress bar is a
|
This is used to display the progress bar. The progress bar is a
|
||||||
@ -206,11 +244,17 @@ System Requirement
|
|||||||
[ActivePerl]: https://www.activestate.com/products/perl/
|
[ActivePerl]: https://www.activestate.com/products/perl/
|
||||||
[File::MMagic]: https://metacpan.org/pod/File::MMagic
|
[File::MMagic]: https://metacpan.org/pod/File::MMagic
|
||||||
[GnuWin32]: http://gnuwin32.sourceforge.net
|
[GnuWin32]: http://gnuwin32.sourceforge.net
|
||||||
[Compress::Zlib]: https://metacpan.org/pod/Compress::Zlib
|
[IO::Compress::Gzip]: https://metacpan.org/pod/IO::Compress::Gzip
|
||||||
|
[IO::Uncompress::Gunzip]: https://metacpan.org/pod/IO::Uncompress::Gunzip
|
||||||
[the gzip website]: https://www.gzip.org
|
[the gzip website]: https://www.gzip.org
|
||||||
[IO-Compress]: https://metacpan.org/release/IO-Compress
|
[IO-Compress]: https://metacpan.org/dist/IO-Compress
|
||||||
[Compress::Bzip2]: https://metacpan.org/pod/Compress::Bzip2
|
[IO::Compress::Bzip2]: https://metacpan.org/pod/IO::Compress::Bzip2
|
||||||
|
[IO::Uncompress::Bunzip2]: https://metacpan.org/pod/IO::Uncompress::Bunzip2
|
||||||
[the bzip2 website]: http://www.bzip.org
|
[the bzip2 website]: http://www.bzip.org
|
||||||
|
[IO::Compress::Xz]: https://metacpan.org/pod/IO::Compress::Xz
|
||||||
|
[IO::Uncompress::UnXz]: https://metacpan.org/pod/IO::Uncompress::UnXz
|
||||||
|
[IO-Compress-Lzma]: https://metacpan.org/dist/IO-Compress-Lzma
|
||||||
|
[the XZ Utils website]: https://tukaani.org/xz/
|
||||||
[Term::ReadKey]: https://metacpan.org/pod/Term::ReadKey
|
[Term::ReadKey]: https://metacpan.org/pod/Term::ReadKey
|
||||||
|
|
||||||
|
|
||||||
@ -373,7 +417,8 @@ Options
|
|||||||
The log file to be resolved. You can specify multiple log files.
|
The log file to be resolved. You can specify multiple log files.
|
||||||
If not specified, it reads from `STDIN` and outputs to `STDOUT`.
|
If not specified, it reads from `STDIN` and outputs to `STDOUT`.
|
||||||
You can also specify `-` to read from `STDIN`. Result of `STDIN`
|
You can also specify `-` to read from `STDIN`. Result of `STDIN`
|
||||||
goes to `STDOUT`. `gzip` or `bzip2` compressed files are supported.
|
goes to `STDOUT`. `gzip`, `bzip2`, or `xz` compressed files are
|
||||||
|
supported.
|
||||||
|
|
||||||
* `-k`, `--keep mode`
|
* `-k`, `--keep mode`
|
||||||
|
|
||||||
@ -480,7 +525,7 @@ Thanks
|
|||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
|
|
||||||
Copyright (C) 2000-2021 imacat.
|
Copyright (C) 2000-2022 imacat.
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#! /usr/bin/perl -w
|
#! /usr/bin/perl -w
|
||||||
# Test all the possible combination of options
|
# Test all the possible combination of options
|
||||||
|
|
||||||
# Copyright (c) 2005-2021 imacat.
|
# Copyright (c) 2005-2022 imacat.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@ -23,7 +23,7 @@ use warnings;
|
|||||||
use diagnostics;
|
use diagnostics;
|
||||||
use Test;
|
use Test;
|
||||||
|
|
||||||
BEGIN { plan tests => 1341 }
|
BEGIN { plan tests => 1788 }
|
||||||
|
|
||||||
use File::Basename qw(basename);
|
use File::Basename qw(basename);
|
||||||
use File::Path qw(mkpath rmtree);
|
use File::Path qw(mkpath rmtree);
|
||||||
@ -193,7 +193,7 @@ foreach my $st (@SOURCE_TYPES) {
|
|||||||
die unless $_ || $$st{"skip"};
|
die unless $_ || $$st{"skip"};
|
||||||
}
|
}
|
||||||
|
|
||||||
# 85: From STDIN to STDOUT
|
# 149: From STDIN to STDOUT
|
||||||
$_ = eval {
|
$_ = eval {
|
||||||
return if $$st{"skip"};
|
return if $$st{"skip"};
|
||||||
my ($title, $cmd, $ret_no, $out, $err, $logfile, $result);
|
my ($title, $cmd, $ret_no, $out, $err, $logfile, $result);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#! /usr/bin/perl -w
|
#! /usr/bin/perl -w
|
||||||
# Test processing several log files at once
|
# Test processing several log files at once
|
||||||
|
|
||||||
# Copyright (c) 2007-2021 imacat.
|
# Copyright (c) 2007-2022 imacat.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@ -23,7 +23,7 @@ use warnings;
|
|||||||
use diagnostics;
|
use diagnostics;
|
||||||
use Test;
|
use Test;
|
||||||
|
|
||||||
BEGIN { plan tests => 4 }
|
BEGIN { plan tests => 5 }
|
||||||
|
|
||||||
use File::Basename qw(basename);
|
use File::Basename qw(basename);
|
||||||
use File::Path qw(mkpath rmtree);
|
use File::Path qw(mkpath rmtree);
|
||||||
@ -48,13 +48,15 @@ $_ = eval {
|
|||||||
$suf = "." . random_word;
|
$suf = "." . random_word;
|
||||||
do { $trim_suf = "." . random_word; } until $trim_suf ne $suf;
|
do { $trim_suf = "." . random_word; } until $trim_suf ne $suf;
|
||||||
# (2-4 times available compression) log files
|
# (2-4 times available compression) log files
|
||||||
$_ = 2 + (has_no_gzip? 0: 2) + (has_no_bzip2? 0: 2);
|
$_ = 2 + (has_no_gzip? 0: 2) + (has_no_bzip2? 0: 2)
|
||||||
|
+ (has_no_xz? 0: 2);
|
||||||
$num = $_ + int rand $_;
|
$num = $_ + int rand $_;
|
||||||
my %types = qw();
|
my %types = qw();
|
||||||
# At least 2 files for each available compression
|
# At least 2 files for each available compression
|
||||||
foreach my $st (@SOURCE_TYPES) {
|
foreach my $st (@SOURCE_TYPES) {
|
||||||
next if ($$st{"type"} eq TYPE_GZIP && has_no_gzip)
|
next if ($$st{"type"} eq TYPE_GZIP && has_no_gzip)
|
||||||
|| ($$st{"type"} eq TYPE_BZIP2 && has_no_bzip2);
|
|| ($$st{"type"} eq TYPE_BZIP2 && has_no_bzip2)
|
||||||
|
|| ($$st{"type"} eq TYPE_XZ && has_no_xz);
|
||||||
@_ = grep !exists $types{$_}, (0...$num-1);
|
@_ = grep !exists $types{$_}, (0...$num-1);
|
||||||
$types{$_[int rand @_]} = $st;
|
$types{$_[int rand @_]} = $st;
|
||||||
@_ = grep !exists $types{$_}, (0...$num-1);
|
@_ = grep !exists $types{$_}, (0...$num-1);
|
||||||
@ -65,7 +67,8 @@ $_ = eval {
|
|||||||
do {
|
do {
|
||||||
$types{$_} = $SOURCE_TYPES[int rand @SOURCE_TYPES];
|
$types{$_} = $SOURCE_TYPES[int rand @SOURCE_TYPES];
|
||||||
} until !(${$types{$_}}{"type"} eq TYPE_GZIP && has_no_gzip)
|
} until !(${$types{$_}}{"type"} eq TYPE_GZIP && has_no_gzip)
|
||||||
&& !(${$types{$_}}{"type"} eq TYPE_BZIP2 && has_no_bzip2);
|
&& !(${$types{$_}}{"type"} eq TYPE_BZIP2 && has_no_bzip2)
|
||||||
|
&& !(${$types{$_}}{"type"} eq TYPE_XZ && has_no_xz);
|
||||||
}
|
}
|
||||||
@st = map $types{$_}, (0...$num-1);
|
@st = map $types{$_}, (0...$num-1);
|
||||||
@fs = qw();
|
@fs = qw();
|
||||||
@ -122,14 +125,15 @@ $_ = eval {
|
|||||||
ok($_, 1, $@);
|
ok($_, 1, $@);
|
||||||
clean_up $_, $WORKDIR, ++$tno;
|
clean_up $_, $WORKDIR, ++$tno;
|
||||||
|
|
||||||
# 2-4: One of the source log files is read from STDIN
|
# 2-5: One of the source log files is read from STDIN
|
||||||
# The file type at STDIN
|
# The file type at STDIN
|
||||||
foreach my $st_stdin (@SOURCE_TYPES) {
|
foreach my $st_stdin (@SOURCE_TYPES) {
|
||||||
my $skip;
|
my $skip;
|
||||||
$skip = 0;
|
$skip = 0;
|
||||||
$_ = eval {
|
$_ = eval {
|
||||||
if ( ($$st_stdin{"type"} eq TYPE_GZIP && has_no_gzip)
|
if ( ($$st_stdin{"type"} eq TYPE_GZIP && has_no_gzip)
|
||||||
|| ($$st_stdin{"type"} eq TYPE_BZIP2 && has_no_bzip2)) {
|
|| ($$st_stdin{"type"} eq TYPE_BZIP2 && has_no_bzip2)
|
||||||
|
|| ($$st_stdin{"type"} eq TYPE_XZ && has_no_xz)) {
|
||||||
$skip = 1;
|
$skip = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -143,13 +147,15 @@ foreach my $st_stdin (@SOURCE_TYPES) {
|
|||||||
$suf = "." . random_word;
|
$suf = "." . random_word;
|
||||||
do { $trim_suf = "." . random_word; } until $trim_suf ne $suf;
|
do { $trim_suf = "." . random_word; } until $trim_suf ne $suf;
|
||||||
# (2-4 times available compression) log files
|
# (2-4 times available compression) log files
|
||||||
$_ = 2 + (has_no_gzip? 0: 2) + (has_no_bzip2? 0: 2);
|
$_ = 2 + (has_no_gzip? 0: 2) + (has_no_bzip2? 0: 2)
|
||||||
|
+ (has_no_xz? 0: 2);
|
||||||
$num = $_ + int rand $_;
|
$num = $_ + int rand $_;
|
||||||
my %types = qw();
|
my %types = qw();
|
||||||
# At least 2 files for each available compression
|
# At least 2 files for each available compression
|
||||||
foreach my $st (@SOURCE_TYPES) {
|
foreach my $st (@SOURCE_TYPES) {
|
||||||
next if ($$st{"type"} eq TYPE_GZIP && has_no_gzip)
|
next if ($$st{"type"} eq TYPE_GZIP && has_no_gzip)
|
||||||
|| ($$st{"type"} eq TYPE_BZIP2 && has_no_bzip2);
|
|| ($$st{"type"} eq TYPE_BZIP2 && has_no_bzip2)
|
||||||
|
|| ($$st{"type"} eq TYPE_XZ && has_no_xz);
|
||||||
@_ = grep !exists $types{$_}, (0...$num-1);
|
@_ = grep !exists $types{$_}, (0...$num-1);
|
||||||
$types{$_[int rand @_]} = $st;
|
$types{$_[int rand @_]} = $st;
|
||||||
@_ = grep !exists $types{$_}, (0...$num-1);
|
@_ = grep !exists $types{$_}, (0...$num-1);
|
||||||
@ -160,7 +166,8 @@ foreach my $st_stdin (@SOURCE_TYPES) {
|
|||||||
do {
|
do {
|
||||||
$types{$_} = $SOURCE_TYPES[int rand @SOURCE_TYPES];
|
$types{$_} = $SOURCE_TYPES[int rand @SOURCE_TYPES];
|
||||||
} until !(${$types{$_}}{"type"} eq TYPE_GZIP && has_no_gzip)
|
} until !(${$types{$_}}{"type"} eq TYPE_GZIP && has_no_gzip)
|
||||||
&& !(${$types{$_}}{"type"} eq TYPE_BZIP2 && has_no_bzip2);
|
&& !(${$types{$_}}{"type"} eq TYPE_BZIP2 && has_no_bzip2)
|
||||||
|
&& !(${$types{$_}}{"type"} eq TYPE_XZ && has_no_xz);
|
||||||
}
|
}
|
||||||
# Choose the STDIN from the matching compression
|
# Choose the STDIN from the matching compression
|
||||||
@_ = grep ${$types{$_}}{"type"} eq $$st_stdin{"type"}, (0...$num-1);
|
@_ = grep ${$types{$_}}{"type"} eq $$st_stdin{"type"}, (0...$num-1);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#! /usr/bin/perl -w
|
#! /usr/bin/perl -w
|
||||||
# Test the errors that should be captured.
|
# Test the errors that should be captured.
|
||||||
|
|
||||||
# Copyright (c) 2007-2021 imacat.
|
# Copyright (c) 2007-2022 imacat.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@ -21,7 +21,7 @@ use warnings;
|
|||||||
use diagnostics;
|
use diagnostics;
|
||||||
use Test;
|
use Test;
|
||||||
|
|
||||||
BEGIN { plan tests => 7 }
|
BEGIN { plan tests => 9 }
|
||||||
|
|
||||||
use File::Basename qw(basename);
|
use File::Basename qw(basename);
|
||||||
use File::Path qw(mkpath rmtree);
|
use File::Path qw(mkpath rmtree);
|
||||||
@ -35,7 +35,7 @@ $WORKDIR = catdir($FindBin::Bin, "logs");
|
|||||||
$reslog = catfile($FindBin::Bin, updir, "blib", "script", "reslog");
|
$reslog = catfile($FindBin::Bin, updir, "blib", "script", "reslog");
|
||||||
$tno = 0;
|
$tno = 0;
|
||||||
|
|
||||||
# 1-6: Trim suffix is the same as suffix
|
# 1-8: Trim suffix is the same as suffix
|
||||||
foreach my $st (@SOURCE_TYPES) {
|
foreach my $st (@SOURCE_TYPES) {
|
||||||
# 1: Trim suffix is the same as suffix
|
# 1: Trim suffix is the same as suffix
|
||||||
$_ = eval {
|
$_ = eval {
|
||||||
@ -126,7 +126,7 @@ foreach my $st (@SOURCE_TYPES) {
|
|||||||
clean_up $_ || $$st{"skip"}, $WORKDIR, ++$tno;
|
clean_up $_ || $$st{"skip"}, $WORKDIR, ++$tno;
|
||||||
}
|
}
|
||||||
|
|
||||||
# 7: A same log file is specified more than once
|
# 9: A same log file is specified more than once
|
||||||
$_ = eval {
|
$_ = eval {
|
||||||
my ($title, $cmd, $ret_no, $out, $err, %logfiles);
|
my ($title, $cmd, $ret_no, $out, $err, %logfiles);
|
||||||
my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf);
|
my ($fr, $frb, @fle, $fle, $flr, %cef, %crf, %tef, %trf);
|
||||||
|
171
t/_helper.pm
171
t/_helper.pm
@ -1,6 +1,6 @@
|
|||||||
# _helper.pm - A simple test suite helper
|
# _helper.pm - A simple test suite helper
|
||||||
|
|
||||||
# Copyright (c) 2005-2021 imacat
|
# Copyright (c) 2005-2022 imacat
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -25,10 +25,10 @@ $VERSION = "0.05";
|
|||||||
@EXPORT = qw(
|
@EXPORT = qw(
|
||||||
read_file read_raw_file write_file write_raw_file
|
read_file read_raw_file write_file write_raw_file
|
||||||
run_cmd where_is file_type list_files preserve_source clean_up
|
run_cmd where_is file_type list_files preserve_source clean_up
|
||||||
has_no_file has_no_gzip has_no_bzip2
|
has_no_file has_no_gzip has_no_bzip2 has_no_xz
|
||||||
make_log_file make_resolved_log_file make_empty_log_file
|
make_log_file make_resolved_log_file make_empty_log_file
|
||||||
random_word
|
random_word
|
||||||
TYPE_TEXT TYPE_GZIP TYPE_BZIP2
|
TYPE_TEXT TYPE_GZIP TYPE_BZIP2 TYPE_XZ
|
||||||
@CONTENT_TYPES @SOURCE_TYPES @KEEP_MODES @OVERRIDE_MODES @SUFFICES @TRIM_SUFFIX);
|
@CONTENT_TYPES @SOURCE_TYPES @KEEP_MODES @OVERRIDE_MODES @SUFFICES @TRIM_SUFFIX);
|
||||||
# Prototype declaration
|
# Prototype declaration
|
||||||
sub this_file();
|
sub this_file();
|
||||||
@ -45,6 +45,7 @@ sub clean_up($$$);
|
|||||||
sub has_no_file();
|
sub has_no_file();
|
||||||
sub has_no_gzip();
|
sub has_no_gzip();
|
||||||
sub has_no_bzip2();
|
sub has_no_bzip2();
|
||||||
|
sub has_no_xz();
|
||||||
sub make_log_file($);
|
sub make_log_file($);
|
||||||
sub make_resolved_log_file($);
|
sub make_resolved_log_file($);
|
||||||
sub make_empty_log_file($);
|
sub make_empty_log_file($);
|
||||||
@ -60,16 +61,18 @@ use File::Spec::Functions qw(splitdir catdir catfile path);
|
|||||||
use File::Temp qw(tempfile);
|
use File::Temp qw(tempfile);
|
||||||
use Socket;
|
use Socket;
|
||||||
|
|
||||||
our (%WHERE_IS, $HAS_NO_FILE, $HAS_NO_GZIP, $HAS_NO_BZIP2, $RANDOM_IP);
|
our (%WHERE_IS, $HAS_NO_FILE, $HAS_NO_GZIP, $HAS_NO_BZIP2, $HAS_NO_XZ, $RANDOM_IP);
|
||||||
%WHERE_IS = qw();
|
%WHERE_IS = qw();
|
||||||
undef $HAS_NO_FILE;
|
undef $HAS_NO_FILE;
|
||||||
undef $HAS_NO_GZIP;
|
undef $HAS_NO_GZIP;
|
||||||
undef $HAS_NO_BZIP2;
|
undef $HAS_NO_BZIP2;
|
||||||
|
undef $HAS_NO_XZ;
|
||||||
undef $RANDOM_IP;
|
undef $RANDOM_IP;
|
||||||
|
|
||||||
use constant TYPE_TEXT => "text/plain";
|
use constant TYPE_TEXT => "text/plain";
|
||||||
use constant TYPE_GZIP => "application/x-gzip";
|
use constant TYPE_GZIP => "application/x-gzip";
|
||||||
use constant TYPE_BZIP2 => "application/x-bzip2";
|
use constant TYPE_BZIP2 => "application/x-bzip2";
|
||||||
|
use constant TYPE_XZ => "application/x-xz";
|
||||||
|
|
||||||
our (@CONTENT_TYPES, @SOURCE_TYPES, @KEEP_MODES, @OVERRIDE_MODES, @SUFFICES,
|
our (@CONTENT_TYPES, @SOURCE_TYPES, @KEEP_MODES, @OVERRIDE_MODES, @SUFFICES,
|
||||||
@TRIM_SUFFIX);
|
@TRIM_SUFFIX);
|
||||||
@ -94,7 +97,11 @@ our (@CONTENT_TYPES, @SOURCE_TYPES, @KEEP_MODES, @OVERRIDE_MODES, @SUFFICES,
|
|||||||
{ "title" => "bzip2 source",
|
{ "title" => "bzip2 source",
|
||||||
"type" => TYPE_BZIP2,
|
"type" => TYPE_BZIP2,
|
||||||
"suf" => ".bz2",
|
"suf" => ".bz2",
|
||||||
"skip" => has_no_bzip2, }, );
|
"skip" => has_no_bzip2, },
|
||||||
|
{ "title" => "xz source",
|
||||||
|
"type" => TYPE_XZ,
|
||||||
|
"suf" => ".xz",
|
||||||
|
"skip" => has_no_xz, }, );
|
||||||
# All the keep mode information
|
# All the keep mode information
|
||||||
@KEEP_MODES = (
|
@KEEP_MODES = (
|
||||||
{ "title" => "keep default",
|
{ "title" => "keep default",
|
||||||
@ -179,29 +186,21 @@ sub read_file($) {
|
|||||||
|
|
||||||
# a gzip compressed file
|
# a gzip compressed file
|
||||||
if ($file =~ /\.gz$/) {
|
if ($file =~ /\.gz$/) {
|
||||||
# Compress::Zlib
|
# IO::Uncompress::Gunzip
|
||||||
if (eval { require Compress::Zlib;
|
if (eval { require IO::Uncompress::Gunzip; 1; }) {
|
||||||
Compress::Zlib->import(qw(gzopen));
|
my $gz;
|
||||||
1; }) {
|
|
||||||
use Compress::Zlib qw(gzopen);
|
|
||||||
my ($FH, $gz);
|
|
||||||
$content = "";
|
$content = "";
|
||||||
open $FH, $file or die this_file . ": $file: $!";
|
$gz = IO::Uncompress::Gunzip->new($file)
|
||||||
$gz = gzopen($FH, "rb") or die this_file . ": $file: $!";
|
or die this_file . ": $file: $IO::Uncompress::Gunzip::GunzipError";
|
||||||
while (1) {
|
$content = join "", <$gz>;
|
||||||
($gz->gzread($_, 10240) != -1)
|
$gz->close or die this_file . ": $file: $IO::Uncompress::Gunzip::GunzipError";
|
||||||
or die this_file . ": $file: " . $gz->gzerror;
|
|
||||||
$content .= $_;
|
|
||||||
last if length $_ < 10240;
|
|
||||||
}
|
|
||||||
$gz->gzclose and die this_file . ": $file: " . $gz->gzerror;
|
|
||||||
return $content;
|
return $content;
|
||||||
|
|
||||||
# gzip executable
|
# gzip executable
|
||||||
} else {
|
} else {
|
||||||
my ($PH, $CMD);
|
my ($PH, $CMD);
|
||||||
$CMD = where_is "gzip";
|
$CMD = where_is "gzip";
|
||||||
$CMD = "\"$CMD\" -cd \"$file\"";
|
$CMD = "\"$CMD\" -cdf \"$file\"";
|
||||||
open $PH, "$CMD |" or die this_file . ": $CMD: $!";
|
open $PH, "$CMD |" or die this_file . ": $CMD: $!";
|
||||||
$content = join "", <$PH>;
|
$content = join "", <$PH>;
|
||||||
close $PH or die this_file . ": $CMD: $!";
|
close $PH or die this_file . ": $CMD: $!";
|
||||||
@ -210,29 +209,44 @@ sub read_file($) {
|
|||||||
|
|
||||||
# a bzip compressed file
|
# a bzip compressed file
|
||||||
} elsif ($file =~ /\.bz2$/) {
|
} elsif ($file =~ /\.bz2$/) {
|
||||||
# Compress::Bzip2
|
# IO::Uncompress::Bunzip2
|
||||||
if (eval { require Compress::Bzip2;
|
if (eval { require IO::Uncompress::Bunzip2; 1; }) {
|
||||||
Compress::Bzip2->import(2.00);
|
my $bz;
|
||||||
Compress::Bzip2->import(qw(bzopen));
|
|
||||||
1; }) {
|
|
||||||
my ($FH, $bz);
|
|
||||||
$content = "";
|
$content = "";
|
||||||
open $FH, $file or die this_file . ": $file: $!";
|
$bz = IO::Uncompress::Bunzip2->new($file)
|
||||||
$bz = bzopen($FH, "rb") or die this_file . ": $file: $!";
|
or die this_file . ": $file: $IO::Uncompress::Bunzip2::Bunzip2Error";
|
||||||
while (1) {
|
$content = join "", <$bz>;
|
||||||
($bz->bzread($_, 10240) != -1)
|
$bz->close or die this_file . ": $file: $IO::Uncompress::Bunzip2::Bunzip2Error";
|
||||||
or die this_file . ": $file: " . $bz->bzerror;
|
|
||||||
$content .= $_;
|
|
||||||
last if length $_ < 10240;
|
|
||||||
}
|
|
||||||
$bz->bzclose and die this_file . ": $file: " . $bz->bzerror;
|
|
||||||
return $content;
|
return $content;
|
||||||
|
|
||||||
# bzip2 executable
|
# bzip2 executable
|
||||||
} else {
|
} else {
|
||||||
my ($PH, $CMD);
|
my ($PH, $CMD);
|
||||||
$CMD = where_is "bzip2";
|
$CMD = where_is "bzip2";
|
||||||
$CMD = "bzip2 -cd \"$file\"";
|
$CMD = "\"$CMD\" -cdf \"$file\"";
|
||||||
|
open $PH, "$CMD |" or die this_file . ": $CMD: $!";
|
||||||
|
$content = join "", <$PH>;
|
||||||
|
close $PH or die this_file . ": $CMD: $!";
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
# an xz compressed file
|
||||||
|
} elsif ($file =~ /\.xz$/) {
|
||||||
|
# IO::Uncompress::UnXz
|
||||||
|
if (eval { require IO::Uncompress::UnXz; 1; }) {
|
||||||
|
my $xz;
|
||||||
|
$content = "";
|
||||||
|
$xz = IO::Uncompress::UnXz->new($file)
|
||||||
|
or die this_file . ": $file: $IO::Uncompress::UnXz::UnXzError";
|
||||||
|
$content = join "", <$xz>;
|
||||||
|
$xz->close or die this_file . ": $file: $IO::Uncompress::UnXz::UnXzError";
|
||||||
|
return $content;
|
||||||
|
|
||||||
|
# xz executable
|
||||||
|
} else {
|
||||||
|
my ($PH, $CMD);
|
||||||
|
$CMD = where_is "xz";
|
||||||
|
$CMD = "\"$CMD\" -cdf \"$file\"";
|
||||||
open $PH, "$CMD |" or die this_file . ": $CMD: $!";
|
open $PH, "$CMD |" or die this_file . ": $CMD: $!";
|
||||||
$content = join "", <$PH>;
|
$content = join "", <$PH>;
|
||||||
close $PH or die this_file . ": $CMD: $!";
|
close $PH or die this_file . ": $CMD: $!";
|
||||||
@ -275,16 +289,14 @@ sub write_file($$) {
|
|||||||
|
|
||||||
# a gzip compressed file
|
# a gzip compressed file
|
||||||
if ($file =~ /\.gz$/) {
|
if ($file =~ /\.gz$/) {
|
||||||
# Compress::Zlib
|
# IO::Compress::Gzip
|
||||||
if (eval { require Compress::Zlib;
|
if (eval { require IO::Compress::Gzip; 1; }) {
|
||||||
Compress::Zlib->import(qw(gzopen));
|
my $gz;
|
||||||
1; }) {
|
$gz = IO::Compress::Gzip->new($file, -Level => 9)
|
||||||
my ($FH, $gz);
|
or die this_file . ": $file: $IO::Compress::Gzip::GzipError";
|
||||||
open $FH, ">$file" or die this_file . ": $file: $!";
|
($gz->write($content) == length $content)
|
||||||
$gz = gzopen($FH, "wb9") or die this_file . ": $file: $!";
|
or die this_file . ": $file: $IO::Compress::Gzip::GzipError";
|
||||||
($gz->gzwrite($content) == length $content)
|
$gz->close or die this_file . ": $file: $IO::Compress::Gzip::GzipError";
|
||||||
or die this_file . ": $file: " . $gz->gzerror;
|
|
||||||
$gz->gzclose and die this_file . ": $file: " . $gz->gzerror;
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
# gzip executable
|
# gzip executable
|
||||||
@ -300,26 +312,44 @@ sub write_file($$) {
|
|||||||
|
|
||||||
# a bzip compressed file
|
# a bzip compressed file
|
||||||
} elsif ($file =~ /\.bz2$/) {
|
} elsif ($file =~ /\.bz2$/) {
|
||||||
# Compress::Bzip2
|
# IO::Compress::Bzip2
|
||||||
if (eval { require Compress::Bzip2;
|
if (eval { require IO::Compress::Bzip2; 1; }) {
|
||||||
Compress::Bzip2->import(2.00);
|
my $bz;
|
||||||
Compress::Bzip2->import(qw(bzopen));
|
$bz = IO::Compress::Bzip2->new($file, BlockSize100K => 9)
|
||||||
1; }) {
|
or die this_file . ": $file: $IO::Compress::Bzip2::Bzip2Error";
|
||||||
my ($FH, $bz);
|
($bz->write($content) == length $content)
|
||||||
open $FH, ">$file" or die this_file . ": $file: $!";
|
or die this_file . ": $file: $IO::Compress::Bzip2::Bzip2Error";
|
||||||
$bz = bzopen($FH, "wb9") or die this_file . ": $file: $!";
|
$bz->close or die this_file . ": $file: $IO::Compress::Bzip2::Bzip2Error";
|
||||||
if ($content ne "") {
|
|
||||||
($bz->bzwrite($content, length $content) == length $content)
|
|
||||||
or die this_file . ": $file: " . $bz->bzerror;
|
|
||||||
}
|
|
||||||
$bz->bzclose and die this_file . ": $file: " . $bz->bzerror;
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
# bzip2 executable
|
# bzip2 executable
|
||||||
} else {
|
} else {
|
||||||
my ($PH, $CMD);
|
my ($PH, $CMD);
|
||||||
$CMD = where_is "bzip2";
|
$CMD = where_is "bzip2";
|
||||||
$CMD = "\"$CMD\" -9f > \"$file\"";
|
$CMD = "\"$CMD\" -c9f > \"$file\"";
|
||||||
|
open $PH, "| $CMD" or die this_file . ": $CMD: $!";
|
||||||
|
print $PH $content or die this_file . ": $CMD: $!";
|
||||||
|
close $PH or die this_file . ": $CMD: $!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
# an xz compressed file
|
||||||
|
} elsif ($file =~ /\.xz$/) {
|
||||||
|
# IO::Compress::Xz
|
||||||
|
if (eval { require IO::Compress::Xz; 1; }) {
|
||||||
|
my $xz;
|
||||||
|
$xz = IO::Compress::Xz->new($file, Extreme => 1)
|
||||||
|
or die this_file . ": $file: $IO::Compress::Xz::XzError";
|
||||||
|
($xz->write($content) == length $content)
|
||||||
|
or die this_file . ": $file: $IO::Compress::Xz::XzError";
|
||||||
|
$xz->close or die this_file . ": $file: $IO::Compress::Xz::XzError";
|
||||||
|
return;
|
||||||
|
|
||||||
|
# xz executable
|
||||||
|
} else {
|
||||||
|
my ($PH, $CMD);
|
||||||
|
$CMD = where_is "xz";
|
||||||
|
$CMD = "\"$CMD\" -c9f > \"$file\"";
|
||||||
open $PH, "| $CMD" or die this_file . ": $CMD: $!";
|
open $PH, "| $CMD" or die this_file . ": $CMD: $!";
|
||||||
print $PH $content or die this_file . ": $CMD: $!";
|
print $PH $content or die this_file . ": $CMD: $!";
|
||||||
close $PH or die this_file . ": $CMD: $!";
|
close $PH or die this_file . ": $CMD: $!";
|
||||||
@ -418,6 +448,7 @@ sub file_type($) {
|
|||||||
$_ = File::MMagic->new->checktype_filename($file);
|
$_ = File::MMagic->new->checktype_filename($file);
|
||||||
return TYPE_GZIP if /gzip/;
|
return TYPE_GZIP if /gzip/;
|
||||||
return TYPE_BZIP2 if /bzip2/;
|
return TYPE_BZIP2 if /bzip2/;
|
||||||
|
return TYPE_XZ if /xz/;
|
||||||
# All else are text/plain
|
# All else are text/plain
|
||||||
return TYPE_TEXT;
|
return TYPE_TEXT;
|
||||||
}
|
}
|
||||||
@ -426,6 +457,7 @@ sub file_type($) {
|
|||||||
$_ = join "", `"$_" "$file"`;
|
$_ = join "", `"$_" "$file"`;
|
||||||
return TYPE_GZIP if /gzip/;
|
return TYPE_GZIP if /gzip/;
|
||||||
return TYPE_BZIP2 if /bzip2/;
|
return TYPE_BZIP2 if /bzip2/;
|
||||||
|
return TYPE_XZ if /: XZ/;
|
||||||
# All else are text/plain
|
# All else are text/plain
|
||||||
return TYPE_TEXT;
|
return TYPE_TEXT;
|
||||||
}
|
}
|
||||||
@ -499,22 +531,31 @@ sub has_no_file() {
|
|||||||
|
|
||||||
# If we have gzip support somewhere
|
# If we have gzip support somewhere
|
||||||
sub has_no_gzip() {
|
sub has_no_gzip() {
|
||||||
$HAS_NO_GZIP = eval { require Compress::Zlib; 1; }
|
$HAS_NO_GZIP = eval { require IO::Compress::Gzip; require IO::Uncompress::Gunzip; 1; }
|
||||||
|| defined where_is "gzip"?
|
|| defined where_is "gzip"?
|
||||||
0: "Compress::Zlib or gzip executable not available"
|
0: "IO::Compress::Gzip or gzip executable not available"
|
||||||
if !defined $HAS_NO_GZIP;
|
if !defined $HAS_NO_GZIP;
|
||||||
return $HAS_NO_GZIP;
|
return $HAS_NO_GZIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
# If we have bzip2 support somewhere
|
# If we have bzip2 support somewhere
|
||||||
sub has_no_bzip2() {
|
sub has_no_bzip2() {
|
||||||
$HAS_NO_BZIP2 = eval { require Compress::Bzip2; Compress::Bzip2->import(2.00); 1; }
|
$HAS_NO_BZIP2 = eval { require IO::Compress::Bzip2; require IO::Uncompress::Bunzip2; 1; }
|
||||||
|| defined where_is "bzip2"?
|
|| defined where_is "bzip2"?
|
||||||
0: "Compress::Bzip2 v2 or bzip2 executable not available"
|
0: "IO::Compress::Bzip2 v2 or bzip2 executable not available"
|
||||||
if !defined $HAS_NO_BZIP2;
|
if !defined $HAS_NO_BZIP2;
|
||||||
return $HAS_NO_BZIP2;
|
return $HAS_NO_BZIP2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# If we have xz support somewhere
|
||||||
|
sub has_no_xz() {
|
||||||
|
$HAS_NO_XZ = eval { require IO::Compress::Xz; require IO::Uncompress::UnXz; 1; }
|
||||||
|
|| defined where_is "xz"?
|
||||||
|
0: "IO::Compress::Xz or xz executable not available"
|
||||||
|
if !defined $HAS_NO_XZ;
|
||||||
|
return $HAS_NO_XZ;
|
||||||
|
}
|
||||||
|
|
||||||
# Create a normal random log file
|
# Create a normal random log file
|
||||||
sub make_log_file($) {
|
sub make_log_file($) {
|
||||||
local ($_, %_);
|
local ($_, %_);
|
||||||
|
Loading…
Reference in New Issue
Block a user