--- loncom/lond 2004/08/17 10:44:00 1.231 +++ loncom/lond 2004/08/18 11:31:50 1.232 @@ -2,7 +2,7 @@ # The LearningOnline Network # lond "LON Daemon" Server (port "LOND" 5663) # -# $Id: lond,v 1.231 2004/08/17 10:44:00 foxr Exp $ +# $Id: lond,v 1.232 2004/08/18 11:31:50 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -52,12 +52,12 @@ use LONCAPA::lonlocal; use LONCAPA::lonssl; use Fcntl qw(:flock); -my $DEBUG = 0; # Non zero to enable debug log entries. +my $DEBUG = 1; # Non zero to enable debug log entries. my $status=''; my $lastlog=''; -my $VERSION='$Revision: 1.231 $'; #' stupid emacs +my $VERSION='$Revision: 1.232 $'; #' stupid emacs my $remoteVERSION; my $currenthostid="default"; my $currentdomainid; @@ -1756,18 +1756,39 @@ sub fetch_user_file_handler { my $userinput = "$cmd:$tail"; my $fname = $tail; - my ($udom,$uname,$ufile)=split(/\//,$fname); + my ($udom,$uname,$ufile) = ($fname =~ m|^([^/]+)/([^/]+)/(.+)$|); my $udir=&propath($udom,$uname).'/userfiles'; unless (-e $udir) { mkdir($udir,0770); } + Debug("fetch user file for $fname"); if (-e $udir) { $ufile=~s/^[\.\~]+//; - $ufile=~s/\///g; + + # IF necessary, create the path right down to the file. + # Note that any regular files in the way of this path are + # wiped out to deal with some earlier folly of mine. + + my $path = $udir; + if ($ufile =~m|(.+)/([^/]+)$|) { + my @parts=split('/',$1); + foreach my $part (@parts) { + $path .= '/'.$part; + if( -f $path) { + unlink($path); + } + if ((-e $path)!=1) { + mkdir($path,0770); + } + } + } + + my $destname=$udir.'/'.$ufile; my $transname=$udir.'/'.$ufile.'.in.transit'; my $remoteurl='http://'.$clientip.'/userfiles/'.$fname; my $response; + Debug("Remote URL : $remoteurl Transfername $transname Destname: $destname"); alarm(120); { my $ua=new LWP::UserAgent; @@ -1781,6 +1802,7 @@ sub fetch_user_file_handler { &logthis("LWP GET: $message for $fname ($remoteurl)"); &Failure($client, "failed\n", $userinput); } else { + Debug("Renaming $transname to $destname"); if (!rename($transname,$destname)) { &logthis("Unable to move $transname to $destname"); unlink($transname);