[LON-CAPA-cvs] cvs: loncom /auth lonuploadedacc.pm /interface londocs.pm /lonnet/perl lonnet.pm rat lonratsrv.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 11 Feb 2004 00:10:02 -0000


This is a MIME encoded message

--albertel1076458202
Content-Type: text/plain

albertel		Tue Feb 10 19:10:02 2004 EDT

  Modified files:              
    /loncom/interface	londocs.pm 
    /rat	lonratsrv.pm 
    /loncom/lonnet/perl	lonnet.pm 
    /loncom/auth	lonuploadedacc.pm 
  Log:
  - fixes 'delete map on lonc/d communication faliure' 
     - lonupload now returns a 503 when it can't contact the remote machine
     - getfile now returns a -2 on network error     
     - londocs checks for error codes from &storemap
     - &storemap pass error messages along
  
  
--albertel1076458202
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20040210191002.txt"

Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.103 loncom/interface/londocs.pm:1.104
--- loncom/interface/londocs.pm:1.103	Thu Feb  5 10:19:41 2004
+++ loncom/interface/londocs.pm	Tue Feb 10 19:10:01 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.103 2004/02/05 15:19:41 matthew Exp $
+# $Id: londocs.pm,v 1.104 2004/02/11 00:10:01 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -68,10 +68,13 @@
 
 sub storemap {
     my ($coursenum,$coursedom,$map)=@_;
-    $hadchanges=1;
-    return
+    my ($outtext,$errtext)=
       &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
                                 $map,1);
+    if ($errtext) { return ($errtext,2); }
+    
+    $hadchanges=1;
+    return ($errtext,0);
 }
 
 # ----------------------------------------- Return hash with valid author names
@@ -250,7 +253,7 @@
 		join ':', ($name, $url, $ext, 'normal', 'res');
 	}
     }
-    &storemap($coursenum, $coursedom, $folder.'.sequence');
+    return &storemap($coursenum, $coursedom, $folder.'.sequence');
 }
 
 sub editor {
@@ -295,7 +298,12 @@
                   $comment.':'.$url.':'.$ext.':normal:res';
               $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
                                                               $newidx;       
- 	      &storemap($coursenum,$coursedom,$folder.'.sequence');
+
+	      ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.sequence');
+	      if ($fatal) {
+		  $r->print('<p><font color="red">'.$errtext.'</font></p>');
+		  return;
+	      }
 	     }
             }
 	    if ($ENV{'form.cmd'}) {
@@ -335,7 +343,12 @@
                     
                 }
 # Store the changed version
-		&storemap($coursenum,$coursedom,$folder.'.sequence');
+		($errtext,$fatal)=&storemap($coursenum,$coursedom,
+					    $folder.'.sequence');
+		if ($fatal) {
+		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
+		    return;
+		}
             }
 # Group import/search
 	    if ($ENV{'form.importdetail'}) {
@@ -349,21 +362,30 @@
 		    }
 		}
 # Store the changed version
-		group_import($coursenum, $coursedom, $folder, @imports);
+		($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
+					       @imports);
+		if ($fatal) {
+		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
+		    return;
+		}
             }
 # Loading a complete map
 	   if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
-              foreach
-(&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
+	       foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
                    my $idx=$#Apache::lonratedt::resources;
                    $idx++;
                    $Apache::lonratedt::resources[$idx]=$_;
                    $Apache::lonratedt::order
-                            [$#Apache::lonratedt::order+1]=$idx;
-                }
+		       [$#Apache::lonratedt::order+1]=$idx;
+	       }
 
 # Store the changed version
-		&storemap($coursenum,$coursedom,$folder.'.sequence');
+	       ($errtext,$fatal)=&storemap($coursenum,$coursedom,
+					   $folder.'.sequence');
+	       if ($fatal) {
+		   $r->print('<p><font color="red">'.$errtext.'</font></p>');
+		   return;
+	       }
            }
        }
 # ---------------------------------------------------------------- End commands
Index: rat/lonratsrv.pm
diff -u rat/lonratsrv.pm:1.24 rat/lonratsrv.pm:1.25
--- rat/lonratsrv.pm:1.24	Mon Feb  3 13:03:53 2003
+++ rat/lonratsrv.pm	Tue Feb 10 19:10:01 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Server for RAT Maps
 #
-# $Id: lonratsrv.pm,v 1.24 2003/02/03 18:03:53 harris41 Exp $
+# $Id: lonratsrv.pm,v 1.25 2004/02/11 00:10:01 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -67,6 +67,7 @@
 
 sub loadmap {
     my ($fn,$errtext)=@_;
+    if ($errtext) { return('',$errtext); }
     my $outstr='';
     my @obj=();
     my @links=();
@@ -81,7 +82,9 @@
         }
         $instr=join('',@content);
     }
-    if ($instr) {
+    if ($instr eq -2) {
+        $errtext.='Map not loaded: An error occured while trying to load the map.';
+    } elsif ($instr) {
         my $parser = HTML::TokeParser->new(\$instr);
         my $token;
         my $graphmode=0;
@@ -293,9 +296,11 @@
 	if ($fn=~/^\/*uploaded\/(\w+)\/(\w+)\//) {
 	    $ENV{'form.output'}=$outstr;
             my $home=&Apache::lonnet::homeserver($2,$1);
-            &Apache::lonnet::finishuserfileupload(
-              $2,$1,$home,
-              'output',(split(/\//,$fn))[-1]);
+            my $result=&Apache::lonnet::finishuserfileupload($2,$1,$home,
+					       'output',(split(/\//,$fn))[-1]);
+	    if ($result != m|^/uploaded/|) {
+		$errtext.='Map not saved: A network error occured when trying to save the map. ';
+	    }
         } else {
           my $fh;
           if ($fh=Apache::File->new(">$fn")) {
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.471 loncom/lonnet/perl/lonnet.pm:1.472
--- loncom/lonnet/perl/lonnet.pm:1.471	Wed Feb  4 17:39:06 2004
+++ loncom/lonnet/perl/lonnet.pm	Tue Feb 10 19:10:01 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.471 2004/02/04 22:39:06 albertel Exp $
+# $Id: lonnet.pm,v 1.472 2004/02/11 00:10:01 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1232,8 +1232,8 @@
 # Notify homeserver to grep it
 #
     
-    my $fetchresult= 
- &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$fname,$docuhome);
+    my $fetchresult= &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$fname,
+			    $docuhome);
     if ($fetchresult eq 'ok') {
 #
 # Return the URL to it
@@ -3844,7 +3844,7 @@
     # if it is a non metadata possible uri return quickly
     if (($uri eq '') || (($uri =~ m|^/*adm/|) && ($uri !~ m|^adm/includes|)) ||
         ($uri =~ m|/$|) || ($uri =~ m|/.meta$|) || ($uri =~ /^~/) ||
-	($uri =~ m|home/[^/]+/public_html/|)) {
+	($uri =~ m|home/[^/]+/public_html/|) || ($uri =~ m|^uploaded/|)) {
 	return undef;
     }
     my $filename=$uri;
@@ -4415,27 +4415,39 @@
 }
 
 # ------------------------------------------------------------ Serves up a file
-# returns either the contents of the file or a -1
+# returns either the contents of the file or 
+# -1 if the file doesn't exist
+# -2 if an error occured when trying to aqcuire the file
+
 sub getfile {
- my $file=shift;
- if ($file=~/^\/*uploaded\//) { # user file
-    my $ua=new LWP::UserAgent;
-    my $request=new HTTP::Request('GET',&tokenwrapper($file));
-    my $response=$ua->request($request);
-    if ($response->is_success()) {
-       return $response->content;
-    } else { 
-       return -1; 
-    }
- } else { # normal file from res space
-  &repcopy($file);
-  if (! -e $file ) { return -1; };
-  my $fh;
-  open($fh,"<$file");
-  my $a='';
-  while (<$fh>) { $a .=$_; }
-  return $a;
- }
+    my $file=shift;
+    if ($file=~/^\/*uploaded\//) { # user file
+	my $ua=new LWP::UserAgent;
+	my $request=new HTTP::Request('GET',&tokenwrapper($file));
+	my $response=$ua->request($request);
+	if ($response->is_success()) {
+	    return $response->content;
+	} else { 
+	    #&logthis("Return Code is ".$response->code." for $file ".
+	    #         &tokenwrapper($file));
+	    # 500 for ISE when tokenwrapper can't figure out what server to
+            #  contact
+            # 503 when lonuploadacc can't contact the requested server
+	    if ($response->code eq 503 || $response->code eq 500) {
+		return -2;
+	    } else {
+		return -1;
+	    }
+	}
+    } else { # normal file from res space
+	&repcopy($file);
+	if (! -e $file ) { return -1; };
+	my $fh;
+	open($fh,"<$file");
+	my $a='';
+	while (<$fh>) { $a .=$_; }
+	return $a;
+    }
 }
 
 sub filelocation {
Index: loncom/auth/lonuploadedacc.pm
diff -u loncom/auth/lonuploadedacc.pm:1.9 loncom/auth/lonuploadedacc.pm:1.10
--- loncom/auth/lonuploadedacc.pm:1.9	Mon May 12 21:56:32 2003
+++ loncom/auth/lonuploadedacc.pm	Tue Feb 10 19:10:02 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Access Handler for User Files
 #
-# $Id: lonuploadedacc.pm,v 1.9 2003/05/13 01:56:32 www Exp $
+# $Id: lonuploadedacc.pm,v 1.10 2004/02/11 00:10:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -43,7 +43,7 @@
 # H now must ask S if token is valid, uses S's lond-command tokenauthuserfile
 
 use strict;
-use Apache::Constants qw(:common);
+use Apache::Constants qw(:common :http);
 use Apache::lonnet();
 
 sub handler {
@@ -58,9 +58,11 @@
 				     $remoteserver);
     if ($reply eq 'ok') {
        return OK;
+   } elsif ($reply eq 'con_lost' || $reply eq 'no_such_host') {
+       &Apache::lonnet::logthis("Server unavailable for userfile access $uname at $udom for $ufile with $remoteserver token $ENV{'form.token'}: $reply");
+       return HTTP_SERVICE_UNAVAILABLE;
    } else {
-       &Apache::lonnet::logthis(
-"Refused userfile access $uname at $udom for $ufile with $remoteserver token $ENV{'form.token'}: $reply");
+       &Apache::lonnet::logthis("Refused userfile access $uname at $udom for $ufile with $remoteserver token $ENV{'form.token'}: $reply");
        return FORBIDDEN;
    }
 }

--albertel1076458202--