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 $prefix = $file->prefix; 25 my $name = $file->name; 26 if (defined $prefix) { 27 $name = File::Spec->catfile($prefix, $name); 28 } 29 30 diff( \($file->get_content), $name, 31 { FILENAME_A => $name, 32 MTIME_A => $file->mtime, 33 OUTPUT => \*STDOUT 34 } 35 ); 36} 37 38 39 40 41sub usage { 42 return q[ 43 44Usage: ptardiff ARCHIVE_FILE 45 ptardiff -h 46 47 ptardiff is a small program that diffs an extracted archive 48 against an unextracted one, using the perl module Archive::Tar. 49 50 This effectively lets you view changes made to an archives contents. 51 52 Provide the progam with an ARCHIVE_FILE and it will look up all 53 the files with in the archive, scan the current working directory 54 for a file with the name and diff it against the contents of the 55 archive. 56 57 58Options: 59 h Prints this help message 60 61 62Sample Usage: 63 64 $ tar -xzf Acme-Buffy-1.3.tar.gz 65 $ vi Acme-Buffy-1.3/README 66 67 [...] 68 69 $ ptardiff Acme-Buffy-1.3.tar.gz > README.patch 70 71 72See Also: 73 tar(1) 74 ptar 75 Archive::Tar 76 77 ] . $/; 78} 79 80 81 82=head1 NAME 83 84ptardiff - program that diffs an extracted archive against an unextracted one 85 86=head1 DESCRIPTION 87 88 ptardiff is a small program that diffs an extracted archive 89 against an unextracted one, using the perl module Archive::Tar. 90 91 This effectively lets you view changes made to an archives contents. 92 93 Provide the progam with an ARCHIVE_FILE and it will look up all 94 the files with in the archive, scan the current working directory 95 for a file with the name and diff it against the contents of the 96 archive. 97 98=head1 SYNOPSIS 99 100 ptardiff ARCHIVE_FILE 101 ptardiff -h 102 103 $ tar -xzf Acme-Buffy-1.3.tar.gz 104 $ vi Acme-Buffy-1.3/README 105 [...] 106 $ ptardiff Acme-Buffy-1.3.tar.gz > README.patch 107 108 109=head1 OPTIONS 110 111 h Prints this help message 112 113=head1 SEE ALSO 114 115tar(1), L<Archive::Tar>. 116 117=cut 118