version 1.481, 2004/03/31 19:25:08
|
version 1.482, 2004/04/01 14:55:18
|
Line 4566 sub receipt {
|
Line 4566 sub receipt {
|
|
|
sub getfile { |
sub getfile { |
my ($file,$caller) = @_; |
my ($file,$caller) = @_; |
if ($file=~ m|^/*uploaded/(\w+)/(\w+)/(.+)$|) { # user file |
|
my $info; |
if ($file !~ m|^/*uploaded/(\w+)/(\w+)/(.+)$|) { |
my $cdom = $1; |
# normal file from res space |
my $cnum = $2; |
|
my $filename = $3; |
|
my $path = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles'; |
|
my ($lwpresp,$rtncode); |
|
my $localfile = $path.'/'.$cdom.'/'.$cnum.'/'.$filename; |
|
if (-e "$localfile") { |
|
my @fileinfo = stat($localfile); |
|
$lwpresp = &getuploaded('HEAD',$file,$cdom,$cnum,\$info,\$rtncode); |
|
if ($lwpresp eq 'ok') { |
|
if ($info > $fileinfo[9]) { |
|
$info = ''; |
|
$lwpresp = &getuploaded('GET',$file,$cdom,$cnum,\$info,\$rtncode); |
|
if ($lwpresp eq 'ok') { |
|
open (FILE,">$localfile"); |
|
print FILE $info; |
|
close(FILE); |
|
if ($caller eq 'uploadrep') { |
|
return 'ok'; |
|
} else { |
|
return $info; |
|
} |
|
} else { |
|
return -1; |
|
} |
|
} else { |
|
return &readfile($localfile); |
|
} |
|
} else { |
|
if ($rtncode eq '404') { |
|
unlink($localfile); |
|
} |
|
return -1; |
|
} |
|
} else { |
|
$lwpresp = &getuploaded('GET',$file,$cdom,$cnum,\$info,\$rtncode); |
|
if ($lwpresp eq 'ok') { |
|
my @parts = ($cdom,$cnum); |
|
if ($filename =~ m|^(.+)/[^/]+$|) { |
|
push @parts, split(/\//,$1); |
|
} |
|
foreach my $part (@parts) { |
|
$path .= '/'.$part; |
|
if (!-e $path) { |
|
mkdir($path,0770); |
|
} |
|
} |
|
open (FILE,">$localfile"); |
|
print FILE $info; |
|
close(FILE); |
|
if ($caller eq 'uploadrep') { |
|
return 'ok'; |
|
} else { |
|
return $info; |
|
} |
|
} else { |
|
return -1; |
|
} |
|
} |
|
} else { # normal file from res space |
|
&repcopy($file); |
&repcopy($file); |
return &readfile($file); |
return &readfile($file); |
} |
} |
|
|
|
my $info; |
|
my $cdom = $1; |
|
my $cnum = $2; |
|
my $filename = $3; |
|
my $path = $Apache::lonnet::perlvar{'lonDocRoot'}.'/userfiles'; |
|
my ($lwpresp,$rtncode); |
|
my $localfile = $path.'/'.$cdom.'/'.$cnum.'/'.$filename; |
|
if (-e "$localfile") { |
|
my @fileinfo = stat($localfile); |
|
$lwpresp = &getuploaded('HEAD',$file,$cdom,$cnum,\$info,\$rtncode); |
|
if ($lwpresp ne 'ok') { |
|
if ($rtncode eq '404') { |
|
unlink($localfile); |
|
} |
|
return -1; |
|
} |
|
if ($info < $fileinfo[9]) { |
|
return &readfile($localfile); |
|
} |
|
$info = ''; |
|
$lwpresp = &getuploaded('GET',$file,$cdom,$cnum,\$info,\$rtncode); |
|
if ($lwpresp ne 'ok') { |
|
return -1; |
|
} |
|
} else { |
|
$lwpresp = &getuploaded('GET',$file,$cdom,$cnum,\$info,\$rtncode); |
|
if ($lwpresp ne 'ok') { |
|
return -1; |
|
} |
|
my @parts = ($cdom,$cnum); |
|
if ($filename =~ m|^(.+)/[^/]+$|) { |
|
push @parts, split(/\//,$1); |
|
} |
|
foreach my $part (@parts) { |
|
$path .= '/'.$part; |
|
if (!-e $path) { |
|
mkdir($path,0770); |
|
} |
|
} |
|
} |
|
open (FILE,">$localfile"); |
|
print FILE $info; |
|
close(FILE); |
|
if ($caller eq 'uploadrep') { |
|
return 'ok'; |
|
} |
|
return $info; |
} |
} |
|
|
sub getuploaded { |
sub getuploaded { |
Line 4641 sub getuploaded {
|
Line 4630 sub getuploaded {
|
my $request=new HTTP::Request($reqtype,$uri); |
my $request=new HTTP::Request($reqtype,$uri); |
my $response=$ua->request($request); |
my $response=$ua->request($request); |
$$rtncode = $response->code; |
$$rtncode = $response->code; |
if ($response->is_success()) { |
if (! $response->is_success()) { |
if ($reqtype eq 'HEAD') { |
return 'failed'; |
$$info = &Date::Parse::str2time( $response->header('Last-modified') ); |
} |
} elsif ($reqtype eq 'GET') { |
if ($reqtype eq 'HEAD') { |
$$info = $response->content; |
$$info = &Date::Parse::str2time( $response->header('Last-modified') ); |
} |
} elsif ($reqtype eq 'GET') { |
return 'ok'; |
$$info = $response->content; |
} else { |
|
return 'failed'; |
|
} |
} |
|
return 'ok'; |
} |
} |
|
|
sub readfile { |
sub readfile { |