8 our $LastUpdate = -M $0;
12 my $file = shift or die "Need file\n". usage();
13 my $outfile = shift || '';
14 my $mode = (stat($file))[2] & 07777;
16 open my $fh, "<", $file
17 or die "Could not open input file $file: $!";
19 my $str = do { local $/; <$fh> };
26 $outfile =~ s/\.packed//;
28 my ($head, $body) = split /__UU__\n/, $str;
29 die "Can't unpack malformed data in '$file'\n"
31 $outstr = unpack 'u', $body;
34 $outfile ||= $file . '.packed';
36 my $me = basename($0);
38 $outstr = <<"EOFBLURB" . pack 'u', $str;
39 #########################################################################
40 This is a binary file that was packed with the 'uupacktool.pl' which
41 is included in the Perl distribution.
43 To unpack this file use the following command:
47 To recreate it use the following command:
51 Created at @{[scalar localtime]}
52 #########################################################################
61 print "Writing $file into $outfile\n" if $opts->{'v'};
62 open my $outfh, ">", $outfile
63 or die "Could not open $outfile for writing: $!";
68 chmod $mode, $outfile;
71 ### delete source file?
72 if( $opts->{'D'} and $file ne $outfile ) {
79 my $Manifest = $opts->{'m'};
81 open my $fh, "<", $Manifest or die "Could not open '$Manifest':$!";
83 print "Reading $Manifest\n"
88 while( my $line = <$fh> ) {
90 my ($file) = split /\s+/, $line;
94 next unless $file =~ /\.packed/;
102 if( !$opts->{'c'} ) {
103 ( $out, $file ) = ( $file, $out ) if $opts->{'p'};
106 if ($changed < $LastUpdate and $changed < -M $file) {
107 print "Skipping '$file' as '$out' is up-to-date.\n"
112 handle_file($opts, $file, $out);
113 print "Converted '$file' to '$out'\n"
121 print "File '$file' was not unpacked into '$out'. Can not remove.\n";
125 print "Removing '$out'\n";
130 print "Found $count files to process out of $lines in '$Manifest'\n"
136 Usage: $^X $0 [-d dir] [-v] [-c] [-D] -p|-u [orig [packed|-s] | -m [manifest]]
138 Handle binary files in source tree. Can be used to pack or
139 unpack files individiually or as specified by a manifest file.
142 -u Unpack files (defaults to -u unless -p is specified)
144 -c Clean up all unpacked files. Implies -m
146 -D Delete source file after encoding/decoding
148 -s Output to STDOUT rather than OUTPUT_FILE
149 -m Use manifest file, if none is explicitly provided defaults to 'MANIFEST'
151 -d Change directory to dir before processing
154 -h Display this help message
159 GetOptions($opts,'u','p','c','m:s','s','d=s','v','h');
161 die "Can't pack and unpack at the same time!\n", usage()
162 if $opts->{'u'} && $opts->{'p'};
163 die usage() if $opts->{'h'};
165 if ( $opts->{'d'} ) {
167 or die "Failed to chdir to '$opts->{'d'}':$!";
169 $opts->{'u'} = 1 if !$opts->{'p'};
170 binmode STDOUT if $opts->{'s'};
171 if ( exists $opts->{'m'} or exists $opts->{'c'} ) {
172 $opts->{'m'} ||= "MANIFEST";
177 handle_file($opts, @ARGV);
179 die "No file to process specified!\n", usage();