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

raeburn lon-capa-cvs@mail.lon-capa.org
Tue, 09 Mar 2004 16:12:26 -0000


raeburn		Tue Mar  9 11:12:26 2004 EDT

  Modified files:              
    /loncom	lond 
  Log:
  Case where userinput = fetchuserfile, optional fpath may now be included in call to lonnet::reply() in format - 
     &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$fname.
                              ':'.$fpath,$docuhome);
     This allows files to be placed in lonUsers/a/b/c/abc1421y123ioip113/userfiles within a directory structure, e.g., in lonUsers/a/b/c/abc1421y123ioip113/userfiles/102903232/sequences/newfile.sequence (where $fpath = '/102903232/sequences/). 
  
  See lonnet.pm v. 1.476 
  
  
Index: loncom/lond
diff -u loncom/lond:1.181 loncom/lond:1.182
--- loncom/lond:1.181	Mon Mar  8 16:00:15 2004
+++ loncom/lond	Tue Mar  9 11:12:26 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.181 2004/03/08 21:00:15 albertel Exp $
+# $Id: lond,v 1.182 2004/03/09 16:12:26 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -53,7 +53,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.181 $'; #' stupid emacs
+my $VERSION='$Revision: 1.182 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid;
 my $currentdomainid;
@@ -1827,16 +1827,27 @@
 # -------------------------------------- fetch a user file from a remote server
 		} elsif ($userinput =~ /^fetchuserfile/) { # Client clear or enc.
 		    if(isClient) {
-			my ($cmd,$fname)=split(/:/,$userinput);
+			my ($cmd,$fname,$fpath)=split(/:/,$userinput);
 			my ($udom,$uname,$ufile)=split(/\//,$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/^[\.\~]+//;
 			    $ufile=~s/\///g;
-			    my $destname=$udir.'/'.$ufile;
-			    my $transname=$udir.'/'.$ufile.'.in.transit';
-			    my $remoteurl='http://'.$clientip.'/userfiles/'.$fname;
+			    my $destname=$udir.'/'.$fpath.$ufile;
+			    my $transname=$udir.'/'.$fpath.$ufile.'.in.transit';
+			    my $remoteurl='http://'.$clientip.'/userfiles/'.$udom.'/'.$uname.'/'.$fpath.$ufile;
 			    my $response;
 			    {
 				my $ua=new LWP::UserAgent;
@@ -1846,7 +1857,7 @@
 			    if ($response->is_error()) {
 				unlink($transname);
 				my $message=$response->status_line;
-				&logthis("LWP GET: $message for $fname ($remoteurl)");
+				&logthis("LWP GET: $message for $fpath $fname ($remoteurl)");
 				print $client "failed\n";
 			    } else {
 				if (!rename($transname,$destname)) {