3 # Start downloading some file, and update the .down file with its progress
6 require './updown-lib.pl';
8 $down = &get_download($ARGV[0]);
9 $down || die "Download ID $ARGV[0] does not exist!";
10 &can_write_file($down->{'dir'}) || die "Cannot download files to $down->{'dir'}";
12 # Do the download, updating the config file with progress
14 &save_download($down);
15 $error = &do_download($down, \&download_callback, \@paths);
16 $down->{'complete'} = 1;
17 $down->{'error'} = $error if ($error);
18 &save_download($down);
24 delete($down->{'size'});
25 delete($down->{'got'});
26 delete($down->{'finished'});
32 $down->{'size'} = $_[1];
35 # Got some data. Only update the status file every 10 seconds or when
36 # a percent of data is received
37 $down->{'got'} = $_[1];
38 if ($down->{'size'}) {
39 $percent = int($down->{'got'}*100/$down->{'size'});
41 return if ($percent <= $lastpercent &&
42 $now < $lastupdate + 10);
44 $lastpercent = $percent;
49 $down->{'finished'} = 1;
50 $down->{'total'} += $down->{'got'};
53 # Redirecting to new URL
56 &save_download($down);
57 &switch_uid_to($down->{'uid'}, $down->{'gid'});