1#!/usr/bin/perl
2
3BEGIN { pop @INC if $INC[-1] eq '.' }
4use strict;
5use warnings;
6use Archive::Tar;
7use Getopt::Std;
8
9my $opts = {};
10getopts('h:', $opts) or die usage();
11
12die usages() if $opts->{h};
13
14### need Text::Diff -- give a polite error (not a standard prereq)
15unless ( eval { require Text::Diff; Text::Diff->import; 1 } ) {
16    die "\n\t This tool requires the 'Text::Diff' module to be installed\n";
17}
18
19my $arch = shift                        or die usage();
20my $tar  = Archive::Tar->new( $arch )   or die "Couldn't read '$arch': $!";
21
22
23foreach my $file ( $tar->get_files ) {
24    next unless $file->is_file;
25    my $prefix = $file->prefix;
26    my $name = $file->name;
27    if (defined $prefix) {
28        $name = File::Spec->catfile($prefix, $name);
29    }
30
31    diff(   \($file->get_content), $name,
32            {   FILENAME_A  => $name,
33                MTIME_A     => $file->mtime,
34                OUTPUT      => \*STDOUT
35            }
36    );
37}
38
39
40
41
42sub usage {
43    return q[
44
45Usage:  ptardiff ARCHIVE_FILE
46        ptardiff -h
47
48    ptardiff is a small program that diffs an extracted archive
49    against an unextracted one, using the perl module Archive::Tar.
50
51    This effectively lets you view changes made to an archives contents.
52
53    Provide the progam with an ARCHIVE_FILE and it will look up all
54    the files with in the archive, scan the current working directory
55    for a file with the name and diff it against the contents of the
56    archive.
57
58
59Options:
60    h   Prints this help message
61
62
63Sample Usage:
64
65    $ tar -xzf Acme-Buffy-1.3.tar.gz
66    $ vi Acme-Buffy-1.3/README
67
68    [...]
69
70    $ ptardiff Acme-Buffy-1.3.tar.gz > README.patch
71
72
73See Also:
74    tar(1)
75    ptar
76    Archive::Tar
77
78    ] . $/;
79}
80
81
82
83=head1 NAME
84
85ptardiff - program that diffs an extracted archive against an unextracted one
86
87=head1 DESCRIPTION
88
89    ptardiff is a small program that diffs an extracted archive
90    against an unextracted one, using the perl module Archive::Tar.
91
92    This effectively lets you view changes made to an archives contents.
93
94    Provide the progam with an ARCHIVE_FILE and it will look up all
95    the files with in the archive, scan the current working directory
96    for a file with the name and diff it against the contents of the
97    archive.
98
99=head1 SYNOPSIS
100
101    ptardiff ARCHIVE_FILE
102    ptardiff -h
103
104    $ tar -xzf Acme-Buffy-1.3.tar.gz
105    $ vi Acme-Buffy-1.3/README
106    [...]
107    $ ptardiff Acme-Buffy-1.3.tar.gz > README.patch
108
109
110=head1 OPTIONS
111
112    h   Prints this help message
113
114=head1 SEE ALSO
115
116tar(1), L<Archive::Tar>.
117
118=cut
119