[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 01 Apr 2004 14:55:18 -0000


albertel		Thu Apr  1 09:55:18 2004 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - style police
  
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.481 loncom/lonnet/perl/lonnet.pm:1.482
--- loncom/lonnet/perl/lonnet.pm:1.481	Wed Mar 31 14:25:08 2004
+++ loncom/lonnet/perl/lonnet.pm	Thu Apr  1 09:55:18 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.481 2004/03/31 19:25:08 raeburn Exp $
+# $Id: lonnet.pm,v 1.482 2004/04/01 14:55:18 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4566,71 +4566,60 @@
 
 sub getfile {
     my ($file,$caller) = @_;
-    if ($file=~ m|^/*uploaded/(\w+)/(\w+)/(.+)$|) { # user 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 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
+
+    if ($file !~ m|^/*uploaded/(\w+)/(\w+)/(.+)$|) {
+	# normal file from res space
 	&repcopy($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 {
@@ -4641,16 +4630,15 @@
     my $request=new HTTP::Request($reqtype,$uri);
     my $response=$ua->request($request);
     $$rtncode = $response->code;
-    if ($response->is_success()) {
-        if ($reqtype eq 'HEAD') {
-            $$info = &Date::Parse::str2time( $response->header('Last-modified') );
-        } elsif ($reqtype eq 'GET') {
-            $$info = $response->content;
-        }
-        return 'ok';
-    } else {
-        return 'failed';
+    if (! $response->is_success()) {
+	return 'failed';
+    }      
+    if ($reqtype eq 'HEAD') {
+	$$info = &Date::Parse::str2time( $response->header('Last-modified') );
+    } elsif ($reqtype eq 'GET') {
+	$$info = $response->content;
     }
+    return 'ok';
 }
 
 sub readfile {