Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

new

  • Loading branch information...
commit d6f84c1b010ab586f54998fb7205e878404bf5fc 1 parent 03f2160
Mike Schilli authored
98  eg/tarflat
... ...
@@ -0,0 +1,98 @@
  1
+#!/usr/bin/perl
  2
+###########################################
  3
+# tarflat 
  4
+# 2005, Mike Schilli <cpan@perlmeister.com>
  5
+###########################################
  6
+use strict;
  7
+use warnings;
  8
+use Getopt::Std;
  9
+use Pod::Usage;
  10
+use Archive::Tar::Wrapper;
  11
+use Sysadm::Install qw(:all);
  12
+
  13
+use vars qw($CVSVERSION);
  14
+
  15
+$CVSVERSION = '$Revision: 1.1 $';
  16
+
  17
+getopts("hv", \my %opts);
  18
+
  19
+pod2usage() if $opts{h};
  20
+
  21
+if($opts{v}) {
  22
+    my ($version) = $CVSVERSION =~ /(\d\S+)/;
  23
+    die "$0 $version\n";
  24
+}
  25
+
  26
+my($target_dir, @tarfiles) = @ARGV;
  27
+
  28
+if(!defined $target_dir or
  29
+   !@tarfiles) {        
  30
+    pod2usage("Wrong number of arguments");
  31
+}
  32
+
  33
+if(! -d $target_dir) {
  34
+    my $create = ask "$target_dir doesn't exist. Create it [y]", "y";
  35
+    mkd $target_dir if $create =~ /[yY]/;
  36
+}
  37
+
  38
+my $arch = Archive::Tar::Wrapper->new();
  39
+
  40
+for my $tarfile (@tarfiles) {
  41
+    $arch->read($tarfile);
  42
+}
  43
+
  44
+$arch->list_reset();
  45
+
  46
+while(my $entry = $arch->list_next()) {
  47
+    my($tar_path, $phys_path) = @$entry;
  48
+    if(-f $phys_path) {
  49
+        cp $phys_path, $target_dir;
  50
+    }
  51
+}
  52
+
  53
+__END__
  54
+
  55
+=head1 NAME
  56
+
  57
+    tarflat - Unpack tarfiles and put their content flat in a single directory
  58
+
  59
+=head1 SYNOPSIS
  60
+
  61
+    tarflat target_dir tarfile ...
  62
+
  63
+=head1 OPTIONS
  64
+
  65
+=over 8
  66
+
  67
+=item B<-h>
  68
+
  69
+Prints this manual page in text format.
  70
+
  71
+=item B<-v>
  72
+
  73
+Prints the script version.
  74
+
  75
+=back
  76
+
  77
+=head1 DESCRIPTION
  78
+
  79
+C<tarflat> 
  80
+
  81
+=head1 EXAMPLES
  82
+
  83
+      # Unpack foo.tgz and bar.tgz and store all of their files
  84
+      # (anywhere in the directory hierarchy) in the directory
  85
+      # /tmp/junk.
  86
+  $ mkdir /tmp/junk
  87
+  $ tarflat /tmp/junk foo.tgz bar.tgz
  88
+
  89
+=head1 LEGALESE
  90
+
  91
+Copyright 2005 by Mike Schilli, 
  92
+all rights reserved. This program is free 
  93
+software, you can redistribute it and/or
  94
+modify it under the same terms as Perl itself.
  95
+
  96
+=head1 AUTHOR
  97
+
  98
+2005, Mike Schilli <cpan@perlmeister.com>
39  t/002Mult.t
... ...
@@ -0,0 +1,39 @@
  1
+######################################################################
  2
+# Test suite for Archive::Tar::Wrapper
  3
+# by Mike Schilli <cpan@perlmeister.com>
  4
+######################################################################
  5
+
  6
+use warnings;
  7
+use strict;
  8
+use Log::Log4perl qw(:easy);
  9
+use File::Path;
  10
+use File::Temp qw(tempfile);
  11
+
  12
+my $TARDIR = "data";
  13
+$TARDIR = "t/$TARDIR" unless -d $TARDIR;
  14
+my $TMPDIR = "$TARDIR/tmp";
  15
+
  16
+use Test::More tests => 16;
  17
+BEGIN { use_ok('Archive::Tar::Wrapper') };
  18
+
  19
+rmdir $TMPDIR if -d $TMPDIR;
  20
+mkdir $TMPDIR or die "Cannot mkdir $TMPDIR";
  21
+END { rmtree $TMPDIR }
  22
+
  23
+my $arch = Archive::Tar::Wrapper->new(tmpdir => $TMPDIR);
  24
+
  25
+ok($arch->read("$TARDIR/foo.tgz"), "opening compressed tarfile");
  26
+ok($arch->read("$TARDIR/bar.tar"), "opening uncompressed");
  27
+
  28
+my $elements = $arch->list_all();
  29
+my $got = join " ", sort @$elements;
  30
+is($got, "001Basic.t bar/bar.dat bar/foo.dat", "file check");
  31
+
  32
+# Iterators
  33
+$arch->list_reset();
  34
+my @elements = ();
  35
+while(my $entry = $arch->list_next()) {
  36
+    push @elements, $entry->[0];
  37
+}
  38
+$got = join " ", sort @elements;
  39
+is($got, "001Basic.t bar/bar.dat bar/foo.dat", "file check via iterator");
BIN  t/data/bar.tar
Binary file not shown

0 notes on commit d6f84c1

Please sign in to comment.
Something went wrong with that request. Please try again.