Commit | Line | Data |
81a5970e |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use Archive::Tar; |
5 | use Getopt::Std; |
6 | |
7 | my $opts = {}; |
8 | getopts('h:', $opts) or die usage(); |
9 | |
10 | die usages() if $opts->{h}; |
11 | |
12 | ### need Text::Diff -- give a polite error (not a standard prereq) |
13 | unless ( eval { require Text::Diff; Text::Diff->import; 1 } ) { |
14 | die "\n\t This tool requires the 'Text::Diff' module to be installed\n"; |
15 | } |
16 | |
17 | my $arch = shift or die usage(); |
18 | my $tar = Archive::Tar->new( $arch ) or die "Couldn't read '$arch': $!"; |
19 | |
20 | |
21 | foreach my $file ( $tar->get_files ) { |
22 | next unless $file->is_file; |
23 | my $name = $file->name; |
24 | |
25 | diff( \($file->get_content), $name, |
26 | { FILENAME_A => $name, |
27 | MTIME_A => $file->mtime, |
28 | OUTPUT => \*STDOUT |
29 | } |
30 | ); |
31 | } |
32 | |
33 | |
34 | |
35 | |
36 | sub usage { |
37 | return q[ |
38 | |
39 | Usage: ptardiff ARCHIVE_FILE |
40 | ptardiff -h |
41 | |
42 | ptardiff is a small program that diffs an extracted archive |
43 | against an unextracted one, using the perl module Archive::Tar. |
44 | |
45 | This effectively lets you view changes made to an archives contents. |
46 | |
47 | Provide the progam with an ARCHIVE_FILE and it will look up all |
48 | the files with in the archive, scan the current working directory |
49 | for a file with the name and diff it against the contents of the |
50 | archive. |
51 | |
52 | |
53 | Options: |
54 | h Prints this help message |
55 | |
56 | |
57 | Sample Usage: |
58 | |
59 | $ tar -xzf Acme-Buffy-1.3.tar.gz |
60 | $ vi Acme-Buffy-1.3/README |
61 | |
62 | [...] |
63 | |
64 | $ ptardiff Acme-Buffy-1.3.tar.gz > README.patch |
65 | |
66 | |
67 | See Also: |
68 | tar(1) |
69 | ptar |
70 | Archive::Tar |
71 | |
72 | ] . $/; |
73 | } |