[LON-CAPA-dev] File replication on library server

Guy Albertelli II lon-capa-dev@mail.lon-capa.org
Tue, 16 Oct 2007 17:34:26 -0400


Hi Mark,

> I have a small file download routine that pulls together a zip file of
> submissions. This runs fine on an access server, but I tried it this
> morning on my library server and it does not work. It seems the files do
> not end up in the same place as they do on the access server.
> 
> The following chunk of code pulls together uploaded files from students
> into one directory. I'm figuring the issue is that in this case, access
> to files on the library server does not behave like access on the access
> servers. Can someone illuminate me? 8)

You are using filelocation incorrectly.

First argument is a directory that the second argument is relative to,
if it's an absolute reference then on the second argument needs to be
specified.

Yeah, it's not the best function design.

But when used correctly it returns the absolute on disk filename for
the requested file (and gets the access/library server thing correct)



Any hoo this will do it:

 foreach my $student (@$students) {
     my $domain = $student->{'domain'};
     my $username = $student->{'username'};
     my %history = Apache::lonnet::restore($symb,$courseid,$domain,$username);
     my $uploadurl=$history{'resource.0.upload.uploadedurl'};
     if ($uploadurl) {
         # best just to always do this, could be out of date, missing etc
	 &Apache::lonnet::repcopy($uploadedurl);
	 my $filelocation = &Apache::lonnet::filelocation("",$uploadurl);
         #chop($filelocation); err why are you doing this?
 
	 my $filetype = (split(/\./,$filelocation))[-1];
         $filetype =~ s|/||g; # ???
         my $file2 = $destination."file".substr("000".$index,-3).".$filetype";
         $index++;
         copy($filelocation,$file2);
     } else {
         $html .= "NO FILE for $username<br/>\n";
     }
 }


-- 
guy@albertelli.com   0-7-0-6-27,137