Fix tarring to include only filenames
Change-Id: Ibdd55f159adf1855efa811625ce0c308fcd5571e
diff --git a/Changes b/Changes
index 13d40fb..133d7f2 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,6 @@
+0.32 2017-07-04
+ - Fixed tar building process in script.
+
0.31 2017-06-30
- Fixed exit codes in script.
- Use CORE::fc for case folding.
diff --git a/MANIFEST b/MANIFEST
index 679a38e..72ad3c0 100755
--- a/MANIFEST
+++ b/MANIFEST
@@ -104,6 +104,7 @@
t/script/extract.t
t/script/archive.t
t/script/archive_tar.t
+t/script/archive_tar_tempextract.t
t/script/config.t
t/script/base.t
t/corpus/archive.zip
diff --git a/Makefile.PL b/Makefile.PL
index e59ff5e..8f6d1ed 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -40,7 +40,8 @@
'Config::Simple' => 4.58,
'String::Random' => 0.29,
'File::Path' => 2.12,
- 'Archive::Tar::Builder' => 2.5002
+ 'Archive::Tar::Builder' => 2.5002,
+ 'Archive::Tar' => 2.24
},
MIN_PERL_VERSION => '5.014',
test => {
diff --git a/lib/KorAP/XML/Krill.pm b/lib/KorAP/XML/Krill.pm
index bb30a2d..a8aa5d4 100644
--- a/lib/KorAP/XML/Krill.pm
+++ b/lib/KorAP/XML/Krill.pm
@@ -16,7 +16,7 @@
use Data::Dumper;
use File::Spec::Functions qw/catdir catfile catpath splitdir splitpath rel2abs/;
-our $VERSION = '0.31';
+our $VERSION = '0.32';
has 'path';
has [qw/text_sigle doc_sigle corpus_sigle/];
diff --git a/script/korapxml2krill b/script/korapxml2krill
index 98a41be..502727b 100644
--- a/script/korapxml2krill
+++ b/script/korapxml2krill
@@ -24,6 +24,7 @@
use File::Glob ':bsd_glob';
use File::Temp qw/tempdir/;
use File::Path qw(remove_tree make_path);
+use File::Basename;
use Mojo::Collection 'c';
use String::Random qw(random_string);
use IO::File;
@@ -119,6 +120,9 @@
#
# 2017/06/29
# - Fixed exit codes
+#
+# 2017/07/04
+# - Fixed tar building process
# ----------------------------------------------------------
our $LAST_CHANGE = '2017/06/29';
@@ -834,8 +838,10 @@
# Lock filehandle
if (flock($tar_fh, LOCK_EX)) {
+ my $clean_file = fileparse($filename);
+
# Archive and remove file
- $tar_archive->archive($filename);
+ $tar_archive->archive_as($filename => $clean_file);
unlink $filename;
# Unlock filehandle
diff --git a/t/script/archive_tar_tempextract.t b/t/script/archive_tar_tempextract.t
new file mode 100644
index 0000000..2934324
--- /dev/null
+++ b/t/script/archive_tar_tempextract.t
@@ -0,0 +1,61 @@
+#/usr/bin/env perl
+use strict;
+use warnings;
+use File::Basename 'dirname';
+use File::Spec::Functions qw/catdir catfile/;
+use File::Temp qw/:POSIX tempdir/;
+use Mojo::File;
+use Mojo::Util qw/quote/;
+use Mojo::JSON qw/decode_json/;
+use Archive::Tar;
+use IO::Uncompress::Gunzip;
+use Test::More;
+use Test::Output qw/:stdout :stderr :functions/;
+use Data::Dumper;
+use KorAP::XML::Archive;
+use utf8;
+
+my $f = dirname(__FILE__);
+my $script = catfile($f, '..', '..', 'script', 'korapxml2krill');
+
+my $input_base = catdir($f, '..', 'corpus');
+
+# Temporary output
+my $output = File::Temp->newdir(CLEANUP => 0);
+my $temp_ex = File::Temp->newdir(CLEANUP => 0);
+
+my $cache = tmpnam();
+
+my $call = join(
+ ' ',
+ 'perl', $script,
+ 'serial',
+ '-t' => 'Base#tokens_aggr',
+ '-i' => '"archive.zip"',
+ '-i' => '"archives/wpd15*.zip"',
+ '--cache' => $cache,
+ '-ib' => $input_base,
+ '-o' => $output,
+ '--to-tar' => 1,
+ '-temporary-extract' => $temp_ex,
+ '-sequential-extraction' => 1,
+ '--gzip' => 1
+);
+
+# Test without parameters
+my $stdout = stdout_from(sub { system($call) });
+
+my $wpd_archive = catfile($output, 'archives-wpd15.tar');
+my $bsp_archive = catfile($output, 'archive.tar');
+
+ok(-e $wpd_archive, 'Archive exists');
+ok(-e $bsp_archive, 'Archive exists');
+
+my $tar = Archive::Tar->new;
+$tar->read($bsp_archive);
+ok($tar->contains_file('TEST-BSP-1.json.gz'), 'File found');
+
+$tar->read($wpd_archive);
+ok($tar->contains_file('WPD15-A00-00081.json.gz'), 'File found');
+
+done_testing;