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