SVN: toys/rsget.pl: RSGet/Curl.pm rsget.pl
sparky
sparky at pld-linux.org
Wed Sep 16 00:23:07 CEST 2009
Author: sparky
Date: Wed Sep 16 00:23:07 2009
New Revision: 10609
Modified:
toys/rsget.pl/RSGet/Curl.pm
toys/rsget.pl/rsget.pl
Log:
- add outdir and workdir
Modified: toys/rsget.pl/RSGet/Curl.pm
==============================================================================
--- toys/rsget.pl/RSGet/Curl.pm (original)
+++ toys/rsget.pl/RSGet/Curl.pm Wed Sep 16 00:23:07 2009
@@ -8,6 +8,7 @@
use WWW::Curl::Multi;
use URI::Escape;
use File::Copy;
+use File::Path;
use Fcntl qw(SEEK_SET);
my $curl_multi = new WWW::Curl::Multi;
@@ -80,12 +81,14 @@
# if file exists try to continue
my $fn = $get_obj->{_opts}->{fname};
- if ( $fn and -r $fn ) {
+ my $fp = filepath( $settings{workdir}, $get_obj->{_opts}->{dir}, $fn );
+ if ( $fp and -r $fp ) {
my $got = (stat(_))[7];
#p "File '$fn' already exists, trying to continue at $got";
$curl->setopt( CURLOPT_RANGE, "$got-" );
$supercurl->{fname} = $fn;
+ $supercurl->{filepath} = $fp
}
my $fs = $get_obj->{_opts}->{fsize};
@@ -127,6 +130,7 @@
{
my $supercurl = shift;
my $curl = $supercurl->{curl};
+ my $get_obj = $supercurl->{get_obj};
my $time = time;
hadd $supercurl,
@@ -138,7 +142,7 @@
{
my $mime = $curl->getinfo( CURLINFO_CONTENT_TYPE );
if ( $mime =~ m#^text/html# ) {
- $supercurl->{get_obj}->{is_html} = 1;
+ $get_obj->{is_html} = 1;
$supercurl->{size_total} = 0;
return;
}
@@ -159,27 +163,29 @@
if ( my $fn = $supercurl->{fname} ) {
if ( $fname ne $fn ) {
- $supercurl->{get_obj}->log( "WARNING: Name mismatch, shoud be '$fname'" );
+ $get_obj->log( "WARNING: Name mismatch, shoud be '$fname'" );
}
$fname = $supercurl->{fname};
if ( $supercurl->{head} =~ m{^Content-Range:\s*bytes\s*(\d+)-(\d+)(/(\d+))?\s*$}im ) {
my ( $start, $stop ) = ( +$1, +$2 );
$supercurl->{size_total} = +$4 if $3;
- $supercurl->{get_obj}->log( "ERROR: Size mismatch: $supercurl->{fsize} != $supercurl->{size_total}" )
+ $get_obj->log( "ERROR: Size mismatch: $supercurl->{fsize} != $supercurl->{size_total}" )
if $supercurl->{fsize} != $supercurl->{size_total};
- my $old = file_backup( $fn, "copy" );
+ my $fp = $supercurl->{filepath};
+ my $old = file_backup( $fp, "copy" );
my $old_msg = "";
if ( $old ) {
- rename $fn, $old;
- copy( $old, $fn ) || die "Cannot create backup file: $!";
+ rename $fp, $old;
+ copy( $old, $fp ) || die "Cannot create backup file: $!";
+ $old =~ s#.*/##;
$old_msg = ", backup saved as '$old'";
}
- open my $f_out, '+<', $fn;
+ open my $f_out, '+<', $fp;
seek $f_out, $start, SEEK_SET;
- $supercurl->{get_obj}->log( "Continuing at " . bignum( $start ) . $old_msg );
+ $get_obj->log( "Continuing at " . bignum( $start ) . $old_msg );
hadd $supercurl,
file => $f_out,
@@ -194,14 +200,16 @@
$supercurl->{fname} = $fname;
}
- $supercurl->{get_obj}->set_finfo( $supercurl->{fname}, $supercurl->{size_total} );
+ $get_obj->set_finfo( $supercurl->{fname}, $supercurl->{size_total} );
{
- my $fn = $supercurl->{fname};
+ my $fn = $supercurl->{filepath} =
+ filepath( $settings{workdir}, $get_obj->{_opts}->{dir}, $supercurl->{fname} );
my $old = file_backup( $fn, "move" );
if ( $old ) {
- $supercurl->{get_obj}->log( "Old renamed to '$old'" );
rename $fn, $old;
+ $old =~ s#.*/##;
+ $get_obj->log( "Old renamed to '$old'" );
}
open my $f_out, '>', $fn;
$supercurl->{file} = $f_out;
@@ -234,8 +242,20 @@
return length $chunk;
}
+sub filepath
+{
+ my $outdir = shift || '.';
+ my $subdir = shift;
+ my $fname = shift;
-
+ $outdir .= '/' . $subdir if $subdir;
+ unless ( -d $outdir ) {
+ unless ( mkpath( $outdir ) ) {
+ $outdir = '.';
+ }
+ }
+ return $outdir . '/' . $fname;
+}
sub finish
{
@@ -285,6 +305,8 @@
my $func = $get_obj->{after_curl};
if ( $supercurl->{file} ) {
+ rename $supercurl->{filepath},
+ filepath( $settings{outdir}, $get_obj->{_opts}->{dir}, $supercurl->{fname} );
$get_obj->{dlinfo} = sprintf 'DONE %s %s / %s',
$supercurl->{fname},
bignum( $supercurl->{size_got} ),
Modified: toys/rsget.pl/rsget.pl
==============================================================================
--- toys/rsget.pl/rsget.pl (original)
+++ toys/rsget.pl/rsget.pl Wed Sep 16 00:23:07 2009
@@ -19,6 +19,8 @@
use RSGet::Curl;
use RSGet::FileList;
use RSGet::Get;
+use RSGet::Wait;
+use RSGet::Captcha;
use RSGet::Dispatch;
use RSGet::ListManager;
$SIG{CHLD} = "IGNORE";
@@ -29,6 +31,8 @@
logging => 0,
list_lock => '.${file}.swp', # vim-like swap file
errorlog => 0,
+ outdir => '.',
+ workdir => '.',
);
# read options
@@ -110,7 +114,8 @@
next if $time == $lasttime;
$lasttime = $time;
- RSGet::Get::wait_update();
+ RSGet::Wait::wait_update();
+ RSGet::Captcha::captcha_update();
my $getlist = RSGet::FileList::readlist();
if ( $getlist ) {
More information about the pld-cvs-commit
mailing list