#!/usr/bin/perl ## no critic pod use strict; use warnings; =head1 NAME cksum-tgz - Checksum the contents of a tarball =head1 SYNOPSIS cksum-tgz tarball.tgz > tarball.cksum Options: --help --man =head1 DESCRIPTION This is kind of equivalent to unpacking a tarball, running cksum on everything in it, then deleting the stuff that was unpacked. It attempts to keep a minimum of files around on the disk while operating. =head1 OPTIONS =over =item C<--help> Shows a short help message. =item C<--man> Even more help. =back =cut use Getopt::Long 'GetOptions'; use autouse 'Carp' => 'croak'; use autouse 'Pod::Usage' => 'pod2usage'; GetOptions( man => sub { pod2usage( -verbose => 2 ) }, help => sub { pod2usage( -verbose => 1 ) }, ) or pod2usage( -verbose => 0 ); @ARGV == 1 or pod2usage( -verbose => 0 ); my ($tgz) = shift @ARGV; ## no critic noisy open my $tgz_fh, '-|', 'tar', 'xvzf', $tgz or croak "Can't tar xvzf $tgz: $!"; # tar will print a file before it is done so I have this reader to # wait for the next file to get mentioned. my $file_reader = do { my @files; sub { # Add to @files if necessary and possible. while ( @files < 2 and $tgz_fh ) { chomp( my $file = <$tgz_fh> ); if ( not defined $file ) { close $tgz_fh; undef $tgz_fh; } else { push @files, $file; } } if (@files) { return shift @files; } else { return; } }; }; # For each file, cksum it. # For each directory, plan to remove it in LIFO order. my @directories; while ( my $file = $file_reader->() ) { if ( -f $file ) { 0 == system 'cksum', $file or croak "Can't exec cksum $file: $?"; unlink $file or croak "Can't unlink $file: $!"; } elsif ( -d _ ) { unshift @directories, $file; } } # Remove my directories in LIFO order. while (@directories) { my $size_before = @directories; @directories = grep { not rmdir } @directories; last if @directories == $size_before; }

In reply to cksum contents of a tarball by diotalevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.