[LON-CAPA-cvs] cvs: loncom / lond

raeburn lon-capa-cvs@mail.lon-capa.org
Tue, 16 Mar 2004 20:48:49 -0000


raeburn		Tue Mar 16 15:48:49 2004 EDT

  Modified files:              
    /loncom	lond 
  Log:
  Case where userinput = fetchuserfile
   - format of call from lonnet::reply('fetchuserfile:') reverts to lond v 1.181
  
  Directory structure in $fname from lonnet::reply() will now be searched for, and any
  subdirectories that are needed below lonUsers/$dom/1/2/3/$course/userfiles path will 
  be created.
  
  
  
Index: loncom/lond
diff -u loncom/lond:1.183 loncom/lond:1.184
--- loncom/lond:1.183	Tue Mar  9 16:05:13 2004
+++ loncom/lond	Tue Mar 16 15:48:49 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.183 2004/03/09 21:05:13 albertel Exp $
+# $Id: lond,v 1.184 2004/03/16 20:48:49 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -53,7 +53,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.183 $'; #' stupid emacs
+my $VERSION='$Revision: 1.184 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid;
 my $currentdomainid;
@@ -1827,27 +1827,25 @@
 # -------------------------------------- fetch a user file from a remote server
 		} elsif ($userinput =~ /^fetchuserfile/) { # Client clear or enc.
 		    if(isClient) {
-			my ($cmd,$fname,$fpath)=split(/:/,$userinput);
-			my ($udom,$uname,$ufile)=split(/\//,$fname);
+			my ($cmd,$fname)=split(/:/,$userinput);
+			my ($udom,$uname,$ufile) = ($fname =~ /^([^\/]+)\/([^\/]+)\/(.+)$/);
 			my $udir=propath($udom,$uname).'/userfiles';
 			unless (-e $udir) { mkdir($udir,0770); }
 			if (-e $udir) {
-                            unless ($fpath eq '') {
-                                my $filepath = $udir;
-                                my @parts=split(/\//,$fpath);
-                                my $count;
-                                for ($count=0;$count<=$#parts;$count++) {
-                                    $filepath .="/$parts[$count]";
-                                    if ((-e $filepath)!=1) {
-                                        mkdir($filepath,0770);
+                            $ufile=~s/^[\.\~]+//;
+                            my $path = $udir;
+                            if ($ufile =~/(.+)\/([^\/]+)$/) {
+                                my @parts=split(/\//,$1);
+                                foreach my $part (@parts) {
+                                    $path .= '/'.$part;
+                                    if ((-e $path)!=1) {
+                                        mkdir($path,0770);
                                     }
                                 }
                             }
-			    $ufile=~s/^[\.\~]+//;
-			    $ufile=~s/\///g;
-			    my $destname=$udir.'/'.$fpath.$ufile;
-			    my $transname=$udir.'/'.$fpath.$ufile.'.in.transit';
-			    my $remoteurl='http://'.$clientip.'/userfiles/'.$udom.'/'.$uname.'/'.$fpath.$ufile;
+			    my $destname=$udir.'/'.$ufile;
+			    my $transname=$udir.'/'.$ufile.'.in.transit';
+			    my $remoteurl='http://'.$clientip.'/userfiles/'.$fname;
 			    my $response;
 			    {
 				my $ua=new LWP::UserAgent;
@@ -1857,7 +1855,7 @@
 			    if ($response->is_error()) {
 				unlink($transname);
 				my $message=$response->status_line;
-				&logthis("LWP GET: $message for $fpath $fname ($remoteurl)");
+				&logthis("LWP GET: $message for $fname ($remoteurl)");
 				print $client "failed\n";
 			    } else {
 				if (!rename($transname,$destname)) {
@@ -1873,7 +1871,6 @@
 			}
 		    } else {
 			Reply($client, "refused\n", $userinput);
-
 		    }
 # ------------------------------------------ authenticate access to a user file
 		} elsif ($userinput =~ /^tokenauthuserfile/) { # Client only
@@ -1884,7 +1881,7 @@
 			if (open(ENVIN,$perlvar{'lonIDsDir'}.'/'.
 				 $session.'.id')) {
 			    while (my $line=<ENVIN>) {
-				if ($line=~/userfile\.$fname\=/) { $reply='ok'; }
+				if ($line=~ m|userfile\.$fname\=|) { $reply='ok'; }
 			    }
 			    close(ENVIN);
 			    print $client $reply."\n";