use File::Copy ();
use File::Path ();
use File::Spec;
+use POSIX ();
use IPC::Cmd ();
use Parse::CPAN::Meta ();
$default_keywords = [ 'x86' ] unless defined $default_keywords;
$default_distdir = '/usr/portage/distfiles' unless defined $default_distdir;
+ my $timestamp = CPANPLUS::Dist::Gentoo::Maps::get_portage_timestamp(
+ $main_portdir
+ );
+ if (defined $timestamp) {
+ __PACKAGE__->_notify("Portage tree $main_portdir dates back from UNIX timestamp $timestamp");
+ } else {
+ __PACKAGE__->_notify("Unable to get timestamp for portage tree $main_portdir, using gmtime instead");
+ $timestamp = POSIX::mktime(gmtime);
+ }
+ if ($timestamp < CPANPLUS::Dist::Gentoo::Maps::TIMESTAMP) {
+ __PACKAGE__->_abort("Portage tree too old (please run emerge --sync and retry)");
+ return $format_available = 0;
+ }
+
return $format_available = 1;
}
use strict;
use warnings;
+use File::Spec;
+use POSIX ();
+
=head1 NAME
CPANPLUS::Dist::Gentoo::Maps - Map CPAN distribution names, version numbers and license identifiers to their Gentoo counterparts.
return join '.', map int, @parts;
}
+=head2 C<get_portage_timestamp $portage>
+
+Get the numerical timestamp associated with the portage tree located at C<$portage>.
+Requires L<POSIX::strptime>, and returns C<undef> if it is not available.
+
+=cut
+
+sub get_portage_timestamp {
+ my ($portage) = @_;
+
+ {
+ local $@;
+ eval { require POSIX::strptime } or return;
+ }
+
+ my $file = File::Spec->catfile($portage, 'metadata', 'timestamp.chk');
+ return unless -e $file;
+
+ my $timestamp = do {
+ open my $fh, '<', $file or return;
+ local $/;
+ <$fh>;
+ };
+ s/^\s*//, s/\s*$// for $timestamp;
+
+ my $shift = 0;
+ if ($timestamp =~ s/\s+([+-])([0-9]{2})([0-9]{2})$//) {
+ $shift = ($2 * 60 + $3) * 60;
+ $shift = -$shift if $1 eq '-';
+ }
+
+ my $old_lc_all = POSIX::setlocale(POSIX::LC_ALL());
+ POSIX::setlocale(POSIX::LC_ALL(), 'C');
+ $timestamp = POSIX::mktime(
+ POSIX::strptime($timestamp, '%a, %d %b %Y %H:%M:%S')
+ );
+ POSIX::setlocale(POSIX::LC_ALL(), $old_lc_all);
+ $timestamp += $shift;
+
+ return $timestamp;
+}
+
+=head2 C<TIMESTAMP>
+
+Numerical timestamp associated with the revision of the portage tree that was used for generating the corrections to the natural cpan-to-gentoo mapping listed in this module.
+
+=cut
+
+sub TIMESTAMP () { 1339737301 }
+
=head1 SEE ALSO
L<CPANPLUS::Dist::Gentoo>.
printf $fmt, @args;
}
-sub timestamp {
- my $tm = File::Spec->catfile(PORTAGE, 'metadata', 'timestamp.chk');
- return unless -e $tm;
- open my $fh, '<', $tm;
- local $/;
- <$fh>;
-}
-
-my $timestamp = timestamp();
+my $timestamp = CPANPLUS::Dist::Gentoo::Maps::get_portage_timestamp(PORTAGE);
{
my $ua;
if (-e STATE_FILE) {
my $state = Storable::retrieve(STATE_FILE);
- if ($state->[0] eq $timestamp) {
+ if ($state->[0] == $timestamp) {
printf "State retrieved from %s\n", STATE_FILE;
@not_on_cpan = @{ $state->[1] };
@unfindable = @{ $state->[2] };
unless ($already_parsed) {
if (-e DATA_FILE) {
my $data = Storable::retrieve(DATA_FILE);
- if ($data->[0] eq $timestamp) {
+ if ($data->[0] == $timestamp) {
printf "Data retrieved from %s\n", DATA_FILE;
%fetched_uri = %{ $data->[1] };
} else {
my $max = max map length, keys %name_mismatch;
SRC: while (<$src>) {
- print $dst $_;
- if (/^__DATA__$/) {
+ if (/^sub TIMESTAMP/) {
+ print $dst "sub TIMESTAMP () { $timestamp }\n";
+ } elsif (/^__DATA__$/) {
+ print $dst "__DATA__\n";
printf $dst "%s%s %s\n", $_, (' ' x ($max - length)), $name_mismatch{$_}
for sort keys %name_mismatch;
last SRC;
+ } else {
+ print $dst $_;
}
}