#!/usr/bin/perl -w use strict; $|++; ### CONFIG # the CPAN url to fetch my $REMOTE = "http://www.cpan.org/"; # my $REMOTE = "file://Users/merlyn/MIRROR/CPAN/"; # my $REMOTE = "http://fi.cpan.org/"; # my $REMOTE = "http://au.cpan.org/"; # the path to the local mirror # warning: unknown files below this dir are deleted! my $LOCAL = "/Users/merlyn/Perl/MINICPAN/"; # how verbose? false means nothing but errors my $TRACE = 1; ## END CONFIG ## core: use File::Path qw(mkpath); use File::Basename qw(dirname); use File::Spec::Functions qw(catfile); use File::Find qw(find); ## LWP: use URI (); use LWP::Simple qw(mirror RC_OK RC_NOT_MODIFIED); ## Compress::Zlib use Compress::Zlib qw(gzopen $gzerrno); ## first, get index files my_mirror($_) for qw( authors/01mailrc.txt.gz modules/02packages.details.txt.gz modules/03modlist.data.gz ); ## now walk the packages list my $gz = gzopen(catfile($LOCAL, "modules/02packages.details.txt.gz"), +"rb") or die "Cannot open details: $gzerrno"; my $state = 1; while ($gz->gzreadline($_) > 0) { if ($state == 1) { # in header $state = 2 unless /\S/; next; } if ($state == 2) { # blank following header $state = 3; next; } my ($module, $version, $path) = split; my_mirror("authors/id/$path"); } ## finally, clean the files we didn't stick there clean_unmirrored(); exit 0; BEGIN { my %mirrored; sub my_mirror { my $path = shift; my $remote_uri = URI->new_abs($path, $REMOTE)->as_string; my $local_file = catfile($LOCAL, $path); return if $mirrored{$local_file}++; ## presume "authors/id/*" is up to date if it is present return if $path =~ m{^authors/id} and -f $local_file; print "$remote_uri -> $local_file\n" if $TRACE; mkpath(dirname($local_file), 1, 0711); my $status = mirror($remote_uri, $local_file); return if $status == RC_OK or $status == RC_NOT_MODIFIED; warn "$remote_uri: $status!\n"; } sub clean_unmirrored { find sub { return unless -f and not $mirrored{$File::Find::name}; print "removing $File::Find::name\n" if $TRACE; unlink $_ or warn "Cannot remove $File::Find::name: $!"; }, $LOCAL; } }

In reply to Mirror only the installable parts of CPAN by merlyn

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.