error reporting of [$a ; $b] can be a TODO.
[p5sagit/p5-mst-13.2.git] / lib / Archive / Tar / bin / ptar
CommitLineData
291d3373 1#!/usr/bin/perl
2use strict;
3
4use Getopt::Std;
5use Archive::Tar;
6use File::Find;
7
8my $opts = {};
178aef9a 9getopts('dcvzthxf:I', $opts) or die usage();
291d3373 10
11### show the help message ###
12die usage() if $opts->{h};
13
14### enable debugging (undocumented feature)
178aef9a 15local $Archive::Tar::DEBUG = 1 if $opts->{d};
16
17### enable insecure extracting.
18local $Archive::Tar::INSECURE_EXTRACT_MODE = 1 if $opts->{I};
291d3373 19
20### sanity checks ###
21unless ( 1 == grep { defined $opts->{$_} } qw[x t c] ) {
22 die "You need exactly one of 'x', 't' or 'c' options: " . usage();
23}
24
25my $compress = $opts->{z} ? 1 : 0;
26my $verbose = $opts->{v} ? 1 : 0;
27my $file = $opts->{f} ? $opts->{f} : 'default.tar';
28my $tar = Archive::Tar->new();
29
178aef9a 30
291d3373 31if( $opts->{c} ) {
32 my @files;
33 find( sub { push @files, $File::Find::name;
34 print $File::Find::name.$/ if $verbose }, @ARGV );
b90ab6b2 35
36 Archive::Tar->create_archive( $file, $compress, @files );
291d3373 37 exit;
b90ab6b2 38}
291d3373 39
40my $tar = Archive::Tar->new($file, $compress);
41
42if( $opts->{t} ) {
b90ab6b2 43 print map { $_->full_path . $/ } $tar->get_files;
291d3373 44
b90ab6b2 45} elsif( $opts->{x} ) {
291d3373 46 print map { $_->full_path . $/ } $tar->get_files
47 if $verbose;
48 Archive::Tar->extract_archive($file, $compress);
b90ab6b2 49}
291d3373 50
51
52
53sub usage {
54 qq[
b90ab6b2 55Usage: ptar -c [-v] [-z] [-f ARCHIVE_FILE] FILE FILE ...
56 ptar -x [-v] [-z] [-f ARCHIVE_FILE]
57 ptar -t [-z] [-f ARCHIVE_FILE]
291d3373 58 ptar -h
b90ab6b2 59
291d3373 60 ptar is a small, tar look-alike program that uses the perl module
b90ab6b2 61 Archive::Tar to extract, create and list tar archives.
62
291d3373 63Options:
64 x Extract from ARCHIVE_FILE
65 c Create ARCHIVE_FILE from FILE
66 t List the contents of ARCHIVE_FILE
67 f Name of the ARCHIVE_FILE to use. Default is './default.tar'
68 z Read/Write zlib compressed ARCHIVE_FILE (not always available)
69 v Print filenames as they are added or extraced from ARCHIVE_FILE
70 h Prints this help message
178aef9a 71 I Enable 'Insecure Extract Mode', which allows archives to extract
72 files outside the current working directory. (Not advised).
291d3373 73
74See Also:
75 tar(1)
76 Archive::Tar
77
78 \n]
79}
80
b90ab6b2 81=head1 NAME
82
83ptar - a tar-like program written in perl
84
85=head1 DESCRIPTION
86
87ptar is a small, tar look-alike program that uses the perl module
88Archive::Tar to extract, create and list tar archives.
89
90=head1 SYNOPSIS
91
92 ptar -c [-v] [-z] [-f ARCHIVE_FILE] FILE FILE ...
93 ptar -x [-v] [-z] [-f ARCHIVE_FILE]
94 ptar -t [-z] [-f ARCHIVE_FILE]
95 ptar -h
96
97=head1 OPTIONS
98
99 x Extract from ARCHIVE_FILE
100 c Create ARCHIVE_FILE from FILE
101 t List the contents of ARCHIVE_FILE
102 f Name of the ARCHIVE_FILE to use. Default is './default.tar'
103 z Read/Write zlib compressed ARCHIVE_FILE (not always available)
104 v Print filenames as they are added or extraced from ARCHIVE_FILE
105 h Prints this help message
106
107=head1 SEE ALSO
108
109tar(1), L<Archive::Tar>.
110
111=cut