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

From: Mark Lucas <[email-masked]>
Date: Tue, 16 Oct 2007 06:59:38 -0400

Hi,

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)

Thanks!
Mark

# Get the data
    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) {
           my $filelocation = &Apache::lonnet::filelocation($uploadurl);
           chop($filelocation);

           if (!-e $filelocation)
{&Apache::lonnet::repcopy($filelocation)};

           my $file1 = $filelocation;
           $file1 =~ s|uploaded|home/httpd/html/userfiles|;
           my @tmp = split(/\./,$file1);
           my $filetype = pop(@tmp);
           $filetype =~ s|/||g;
           my $file2 =
$destination."file".substr("000".$index,-3).".$filetype";
$index++;
           copy($file1,$file2);
        } else {
           $html .= "NO FILE for $username<br/>\n";
        }
    }

---

From: Guy Albertelli II <[email-masked]>
Date: Tue, 16 Oct 2007 17:34:26 -0400

Hi Mark,

> 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";
     }
 }

-- 
[email-masked]   0-7-0-6-27,137

---

From: Mark Lucas <[email-masked]>
Date: Wed, 17 Oct 2007 10:20:25 -0400

Thanks! I was afraid it was something subtle like that.

Mark