Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Rename files in gzip tarball: No such file in archive: '/path/to/file1.txt'

by Bowlslaw (Acolyte)
on Dec 09, 2017 at 00:03 UTC ( #1205210=perlquestion: print w/replies, xml ) Need Help??

Bowlslaw has asked for the wisdom of the Perl Monks concerning the following question:

This program reads a list of files from the directory specified on the command line, creates an array of hashes, where each file has key path, size, and sha256sum.

I am trying to create a gzipped tarball of the files, where each files is name the checksum appended with the file's original extension. I create a gzipped tarball of the files successfully. However, when I try to use Archive::Tar's rename method, I am met with this error: No such file in archive: '/path/to/file1.txt' at ./program.pl line 62. This error repeats for each file in the archive.

Is it because the archive is just a flat list of files? If so, how does one use the rename method?

use strict; use warnings; use Data::Dumper qw(Dumper); use File::Spec qw(catfile rel2abs); use Digest::SHA qw(sha256_hex); use Archive::Tar; use Archive::Tar::File; my $dir = $ARGV[0]; my $url = $ARGV[1]; my @AoH; my @checksumfiles; my $tar = Archive::Tar->new; my $archive = "archive.tar.gz"; opendir DIR, $dir or die "cannot open dir $dir: $!\n"; chdir $dir or die "cannot navigate to dir $dir: $!\n"; while(my $file = readdir DIR) { next unless(-f File::Spec->catfile($dir, $file)); next if($file =~ m/^\./); my $fullpath = File::Spec->rel2abs($file); my $fullsize = -s File::Spec->catfile($dir, $file); my $fullid = sha256_hex($fullpath); my %hash = ( path => $fullpath, size => $fullsize, id => $fullid, ); push(@AoH, \%hash); } my @array; for my $i(0..$#AoH) { no warnings 'uninitialized'; my ($ext) = $AoH[$i]{path} =~ (/(\.[^.]+)$/); my $idext = $AoH[$i]{id} . $ext; push(@checksumfiles, $idext); push(@array, $AoH[$i]{path}); } Archive::Tar->create_archive($archive, COMPRESS_GZIP, @array); #print Archive::Tar->list_archive($archive, COMPRESS_GZIP), "\n"; for my $i(0..$#array) { $tar->rename($array[$i], $checksumfiles[$i]); } print Dumper sort \@array; print Dumper sort \@checksumfiles; #print Dumper sort \@AoH;

Replies are listed 'Best First'.
Re: Rename files in gzip tarball: No such file in archive: '/path/to/file1.txt'
by tinita (Parson) on Dec 09, 2017 at 00:51 UTC
      Sorry, I will be sure to list it if this happens again.
Re: Rename files in gzip tarball: No such file in archive: '/path/to/file1.txt'
by karlgoethebier (Abbot) on Dec 09, 2017 at 19:27 UTC

    Just an idea:

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1205210]
Approved by Paladin
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2021-03-06 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (116 votes). Check out past polls.

    Notices?