[LON-CAPA-cvs] cvs: loncom /homework essayresponse.pm grades.pm /interface lonaboutme.pm lonclonecourse.pm loncommon.pm lonhelper.pm lonindexer.pm portfolio.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Mon Oct 17 08:41:40 EDT 2011


raeburn		Mon Oct 17 12:41:40 2011 EDT

  Modified files:              
    /loncom/interface	lonaboutme.pm lonclonecourse.pm loncommon.pm 
                     	lonhelper.pm lonindexer.pm portfolio.pm 
    /loncom/homework	grades.pm essayresponse.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Change to way lonnet::dirlist() reports an error condition (i.e., no_host, 
    con_lost, no_such_dir, empty etc.) when retrieving directory list information
    with ls3, ls2 or ls.
    - error is passed as second item in a pair of return values.
    - first item in return values is a reference to an array of actual files.
  
  
-------------- next part --------------
Index: loncom/interface/lonaboutme.pm
diff -u loncom/interface/lonaboutme.pm:1.147 loncom/interface/lonaboutme.pm:1.148
--- loncom/interface/lonaboutme.pm:1.147	Sun Sep 26 02:02:42 2010
+++ loncom/interface/lonaboutme.pm	Mon Oct 17 12:41:30 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Personal Information Page
 #
-# $Id: lonaboutme.pm,v 1.147 2010/09/26 02:02:42 raeburn Exp $
+# $Id: lonaboutme.pm,v 1.148 2011/10/17 12:41:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -777,9 +777,12 @@
     my $portfolio_root = &Apache::portfolio::get_portfolio_root($cdom,$cnum,
                                                                 $group);
     my $getpropath = 1;
-    my %dirlist = map {
-        ((split('&',$_,2))[0],1)
-    } &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
+    my ($listref,$listerror) =
+        &Apache::lonnet::dirlist($portfolio_root.$path,$cdom,$cnum,$getpropath);
+    my %dirlist;
+    if (ref($listref) eq 'ARRAY') {
+        %dirlist = map { ((split('&',$_,2))[0],1) } @{$listref};
+    }
     foreach my $item (sort(keys(%{$currhash}))) {
         $output .= &Apache::loncommon::start_data_table_row();
         $output .= '<td style="padding-left: '.($depth*25).'px">';
Index: loncom/interface/lonclonecourse.pm
diff -u loncom/interface/lonclonecourse.pm:1.7 loncom/interface/lonclonecourse.pm:1.8
--- loncom/interface/lonclonecourse.pm:1.7	Thu Sep 11 13:19:28 2008
+++ loncom/interface/lonclonecourse.pm	Mon Oct 17 12:41:30 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # routines for clone a course
 #
-# $Id: lonclonecourse.pm,v 1.7 2008/09/11 13:19:28 raeburn Exp $
+# $Id: lonclonecourse.pm,v 1.8 2011/10/17 12:41:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -48,20 +48,23 @@
     unless ($path)  { $path=''; } else { $path.='/'; }
     my %crsdata=&Apache::lonnet::coursedescription($courseid);
     my $getpropath = 1;
-    my @listing=&Apache::lonnet::dirlist
-	($which,$crsdata{'domain'},$crsdata{'num'},$getpropath);
-    foreach (@listing) {
-	unless ($_=~/^\./) {
-	    my @unpackline = split (/\&/,$_);
-	    if ($unpackline[3]&$dirptr) {
+    my ($dirlistref,$listerror) = 
+        &Apache::lonnet::dirlist($which,$crsdata{'domain'},
+                                 $crsdata{'num'},$getpropath);
+    if (ref($dirlistref) eq 'ARRAY') {
+        foreach (@{$dirlistref}) {
+	    unless ($_=~/^\./) {
+	        my @unpackline = split (/\&/,$_);
+	        if ($unpackline[3]&$dirptr) {
 # is a directory, recurse
-		&innercrsdirlist($courseid,$which.$unpackline[0],
-				            $path.$unpackline[0]);
-	    } else { 
+		    &innercrsdirlist($courseid,$which.$unpackline[0],
+				     $path.$unpackline[0]);
+	        } else { 
 # is a file, put into output
-		push (@output,$path.$unpackline[0]);
+		    push (@output,$path.$unpackline[0]);
+	        }
 	    }
-	}
+        }
     }
     return @output;
 }
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1020 loncom/interface/loncommon.pm:1.1021
--- loncom/interface/loncommon.pm:1.1020	Fri Sep  9 20:13:18 2011
+++ loncom/interface/loncommon.pm	Mon Oct 17 12:41:30 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1020 2011/09/09 20:13:18 raeburn Exp $
+# $Id: loncommon.pm,v 1.1021 2011/10/17 12:41:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -8499,10 +8499,13 @@
     foreach my $path (keys(%subdependencies)) {
         my %currsubfile;
         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { 
-            my @subdir_list = &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
-            foreach my $line (@subdir_list) {
-                my ($file_name,$rest) = split(/\&/,$line,2);
-                $currsubfile{$file_name} = 1;
+            my ($sublistref,$listerror) =
+                &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
+            if (ref($sublistref) eq 'ARRAY') {
+                foreach my $line (@{$sublistref}) {
+                    my ($file_name,$rest) = split(/\&/,$line,2);
+                    $currsubfile{$file_name} = 1;
+                }
             }
         } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
             if (opendir(my $dir,$url.'/'.$path)) {
@@ -8525,10 +8528,13 @@
     }
     my %currfile;
     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
-        my @dir_list = &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
-        foreach my $line (@dir_list) {
-            my ($file_name,$rest) = split(/\&/,$line,2);
-            $currfile{$file_name} = 1;
+        my ($dirlistref,$listerror) =
+            &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
+        if (ref($dirlistref) eq 'ARRAY') {
+            foreach my $line (@{$dirlistref}) {
+                my ($file_name,$rest) = split(/\&/,$line,2);
+                $currfile{$file_name} = 1;
+            }
         }
     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
         if (opendir(my $dir,$url)) {
@@ -9048,8 +9054,8 @@
     }
     $filesize =  $filesize/1000; #express in k (1024?)
     my $getpropath = 1;
-    my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
-                                            $getpropath);
+    my ($dirlistref,$listerror) =
+         &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
     my $found_file = 0;
     my $locked_file = 0;
     my @lockers;
@@ -9057,48 +9063,50 @@
     if ($env{'request.course.id'}) {
         $navmap = Apache::lonnavmaps::navmap->new();
     }
-    foreach my $line (@dir_list) {
-        my ($file_name,$rest)=split(/\&/,$line,2);
-        if ($file_name eq $fname){
-            $file_name = $path.$file_name;
-            if ($group ne '') {
-                $file_name = $group.$file_name;
-            }
-            $found_file = 1;
-            if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
-                foreach my $lock (@lockers) {
-                    if (ref($lock) eq 'ARRAY') {
-                        my ($symb,$crsid) = @{$lock};
-                        if ($crsid eq $env{'request.course.id'}) {
-                            if (ref($navmap)) {
-                                my $res = $navmap->getBySymb($symb);
-                                foreach my $part (@{$res->parts()}) { 
-                                    my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
-                                    unless (($slot_status == $res->RESERVED) ||
-                                            ($slot_status == $res->RESERVED_LOCATION)) {
-                                        $locked_file = 1;
+    if (ref($dirlistref) eq 'ARRAY') {
+        foreach my $line (@{$dirlistref}) {
+            my ($file_name,$rest)=split(/\&/,$line,2);
+            if ($file_name eq $fname){
+                $file_name = $path.$file_name;
+                if ($group ne '') {
+                    $file_name = $group.$file_name;
+                }
+                $found_file = 1;
+                if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
+                    foreach my $lock (@lockers) {
+                        if (ref($lock) eq 'ARRAY') {
+                            my ($symb,$crsid) = @{$lock};
+                            if ($crsid eq $env{'request.course.id'}) {
+                                if (ref($navmap)) {
+                                    my $res = $navmap->getBySymb($symb);
+                                    foreach my $part (@{$res->parts()}) { 
+                                        my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
+                                        unless (($slot_status == $res->RESERVED) ||
+                                                ($slot_status == $res->RESERVED_LOCATION)) {
+                                            $locked_file = 1;
+                                        }
                                     }
+                                } else {
+                                    $locked_file = 1;
                                 }
                             } else {
                                 $locked_file = 1;
                             }
-                        } else {
-                            $locked_file = 1;
                         }
-                    }
-                }
-            } else {
-                my @info = split(/\&/,$rest);
-                my $currsize = $info[6]/1000;
-                if ($currsize < $filesize) {
-                    my $extra = $filesize - $currsize;
-                    if (($current_disk_usage + $extra) > $disk_quota) {
-                        my $msg = '<span class="LC_error">'.
-                                  &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
-                                      '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
-                                  '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
-                                               $disk_quota,$current_disk_usage);
-                        return ('will_exceed_quota',$msg);
+                   }
+                } else {
+                    my @info = split(/\&/,$rest);
+                    my $currsize = $info[6]/1000;
+                    if ($currsize < $filesize) {
+                        my $extra = $filesize - $currsize;
+                        if (($current_disk_usage + $extra) > $disk_quota) {
+                            my $msg = '<span class="LC_error">'.
+                                      &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
+                                          '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
+                                      '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
+                                                   $disk_quota,$current_disk_usage);
+                            return ('will_exceed_quota',$msg);
+                        }
                     }
                 }
             }
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.182 loncom/interface/lonhelper.pm:1.183
--- loncom/interface/lonhelper.pm:1.182	Sun Oct 31 15:54:25 2010
+++ loncom/interface/lonhelper.pm	Mon Oct 17 12:41:30 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # .helper XML handler to implement the LON-CAPA helper
 #
-# $Id: lonhelper.pm,v 1.182 2010/10/31 15:54:25 raeburn Exp $
+# $Id: lonhelper.pm,v 1.183 2011/10/17 12:41:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2971,7 +2971,7 @@
     }
 
     # Get the list of files in this directory.
-    my @fileList;
+    my (@fileList,$listref,$listerror);
 
     # If the subdirectory is in local CSTR space
     my $metadir;
@@ -2980,21 +2980,26 @@
 	    &Apache::loncacc::constructaccess($subdir,
 				     $Apache::lonnet::perlvar{'lonDefDomain'});
 	$metadir='/res/'.$domain.'/'.$user.'/'.$2;
-        @fileList = &Apache::lonnet::dirlist($subdir,$domain,$user,undef,undef,'/');
+        ($listref,$listerror) =
+            &Apache::lonnet::dirlist($subdir,$domain,$user,undef,undef,'/');
     } elsif ($subdir =~ m|^~([^/]+)/(.*)$|) {
 	$subdir='/home/'.$1.'/public_html/'.$2;
 	my ($user,$domain)= 
 	    &Apache::loncacc::constructaccess($subdir,
 				     $Apache::lonnet::perlvar{'lonDefDomain'});
 	$metadir='/res/'.$domain.'/'.$user.'/'.$2;
-        @fileList = &Apache::lonnet::dirlist($subdir,$domain,$user,undef,undef,'/');
+        ($listref,$listerror) =
+            &Apache::lonnet::dirlist($subdir,$domain,$user,undef,undef,'/');
     } else {
         # local library server resource space
-        @fileList = &Apache::lonnet::dirlist($subdir,$env{'user.domain'},$env{'user.name'},undef,undef,'/');
+        ($listref,$listerror) = 
+            &Apache::lonnet::dirlist($subdir,$env{'user.domain'},$env{'user.name'},undef,undef,'/');
     }
 
     # Sort the fileList into order
-    @fileList = sort {lc($a) cmp lc($b)} @fileList;
+    if (ref($listref) eq 'ARRAY') {
+        @fileList = sort {lc($a) cmp lc($b)} @{$listref};
+    }
 
     $result .= $buttons;
 
Index: loncom/interface/lonindexer.pm
diff -u loncom/interface/lonindexer.pm:1.210 loncom/interface/lonindexer.pm:1.211
--- loncom/interface/lonindexer.pm:1.210	Fri Oct 14 16:58:32 2011
+++ loncom/interface/lonindexer.pm	Mon Oct 17 12:41:30 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Directory Indexer
 #
-# $Id: lonindexer.pm,v 1.210 2011/10/14 16:58:32 dseaton Exp $
+# $Id: lonindexer.pm,v 1.211 2011/10/17 12:41:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -755,6 +755,7 @@
 sub get_list {
     my ($r,$uri)=@_;
     my @list=();
+    my $listerror;
     
     (my $luri = $uri) =~ s/\//_/g;
     if ($env{'form.updatedisplay'}) {
@@ -779,15 +780,17 @@
 	$hash{'dirlist_files_'.$luri} = join("\n", at list);
     } else {
 # is really a directory
-	@list = &Apache::lonnet::dirlist($uri);
+	(my $listref,$listerror) = &Apache::lonnet::dirlist($uri);
+        if (ref($listref) eq 'ARRAY') {
+            @list = @{$listref};
+        }
 	$hash{'dirlist_files_'.$luri} = join("\n", at list);
 	$hash{'dirlist_timestamp_files_'.$luri} = time;
     }
 #Checking for error messages associated with empty directories or inaccessible servers (See Bug 4984)
-    if($list[0] eq 'no_such_dir' || $list[0] eq 'no_such_host') { 
+    if (($listerror eq 'no_such_dir') || ($listerror eq 'no_such_host')) { 
         $r->print("<p class='LC_info'>" . &mt("Directory does not exist."). "</p>");
-    }
-    elsif($list[0] eq 'con_lost') {
+    } elsif ($listerror eq 'con_lost') {
         $r->print("<p class='LC_info'>" . &mt("Directory temporarily not accessible."). "</p>");
     }
 
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.232 loncom/interface/portfolio.pm:1.233
--- loncom/interface/portfolio.pm:1.232	Fri May 27 18:55:54 2011
+++ loncom/interface/portfolio.pm	Mon Oct 17 12:41:30 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # portfolio browser
 #
-# $Id: portfolio.pm,v 1.232 2011/05/27 18:55:54 raeburn Exp $
+# $Id: portfolio.pm,v 1.233 2011/10/17 12:41:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -379,22 +379,24 @@
     my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path;
     my @dir_lines;
     my %versioned;
-    foreach my $dir_line (sort 
-		      { 
-			  my ($afile)=split('&',$a,2);
-			  my ($bfile)=split('&',$b,2);
-			  return (lc($afile) cmp lc($bfile));
-		      } (@$dir_list)) {
-    	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16); 
-    	$filename =~ s/\s+$//;
-    	my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
-    	if ($version) {
-	    my $fullpath = &prepend_group($current_path.$fname.'.'.$extension);
-    	    push(@{ $versioned{$fullpath} },
-		 [$filename,$dom,$testdir,$size,$mtime,$obs,]);
-    	} else {
-    	    push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
-    	}
+    if (ref($dir_list) eq 'ARRAY') { 
+        foreach my $dir_line (sort 
+		          { 
+			      my ($afile)=split('&',$a,2);
+			      my ($bfile)=split('&',$b,2);
+			      return (lc($afile) cmp lc($bfile));
+		          } (@{$dir_list})) {
+    	    my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16); 
+    	    $filename =~ s/\s+$//;
+    	    my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
+    	    if ($version) {
+	        my $fullpath = &prepend_group($current_path.$fname.'.'.$extension);
+    	        push(@{ $versioned{$fullpath} },
+		     [$filename,$dom,$testdir,$size,$mtime,$obs,]);
+    	    } else {
+    	        push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
+    	    }
+        }
     }
     my $zerobyte;
     foreach my $dir_line (@dir_lines) {
@@ -2249,12 +2251,14 @@
 	    return;
     }
     my $portfolio_root = &get_portfolio_root(); 
-    my @dir_list=&get_dir_list($portfolio_root,undef,$group);
+    my ($dirlistref,$listerror) = &get_dir_list($portfolio_root,undef,$group);
     my $found_file = 0;
-    foreach my $line (@dir_list) {
-        my ($filename)=split(/\&/,$line,2);
-        if ($filename eq $newdir){
-            $found_file = 1;
+    if (ref($dirlistref) eq 'ARRAY') {
+        foreach my $line (@{$dirlistref}) {
+            my ($filename)=split(/\&/,$line,2);
+            if ($filename eq $newdir){
+                $found_file = 1;
+            }
         }
     }
     if ($found_file){
@@ -2703,8 +2707,9 @@
             &Apache::lonhtmlcommon::clear_breadcrumbs();
             $r->print(&coursegrp_portfolio_header($udom,$uname,$grp_desc));
         }
-        my @dir_list=&get_dir_list($portfolio_root,$current_path,$group);
-	if ($dir_list[0] eq 'no_such_dir'){
+        my ($dirlistref,$listerror) =
+            &get_dir_list($portfolio_root,$current_path,$group);
+	if ($listerror eq 'no_such_dir'){
 	    # two main reasons for this:
             #    1) never been here, so directory structure not created
 	    #    2) back-button navigation after deleting a directory
@@ -2719,13 +2724,22 @@
 		$current_path = '/'; # force it back to the root        
 	    }
 	    # now grab the directory list again, for the first time
-            @dir_list=&get_dir_list($portfolio_root,$current_path,$group);
+            ($dirlistref,$listerror) =
+                &get_dir_list($portfolio_root,$current_path,$group);
         }
 	# need to know if directory is empty so it can be removed if desired
-	my $is_empty=(@dir_list == 2);
-	&display_common($r,$url,$current_path,$is_empty,\@dir_list,
+        my $is_empty;
+        if ($listerror eq 'empty') {
+            $is_empty = 1;
+        } elsif (ref($dirlistref) eq 'ARRAY') {
+            if ((scalar(@{$dirlistref}) == 2) && ($dirlistref->[0] =~ /^\.+\&/)
+                && ($dirlistref->[1] =~ /^\.+\&/))  {
+                $is_empty = 1;
+            }
+        }
+	&display_common($r,$url,$current_path,$is_empty,$dirlistref,
 			$can_upload,$group);
-        &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group,
+        &display_directory($r,$url,$current_path,$is_empty,$dirlistref,$group,
                            $can_upload,$can_modify,$can_delete,$can_setacl);
     }
     $r->print(&Apache::loncommon::end_page());
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.661 loncom/homework/grades.pm:1.662
--- loncom/homework/grades.pm:1.661	Tue Oct 11 18:04:40 2011
+++ loncom/homework/grades.pm	Mon Oct 17 12:41:34 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.661 2011/10/11 18:04:40 www Exp $
+# $Id: grades.pm,v 1.662 2011/10/17 12:41:34 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2905,8 +2905,10 @@
 		        &file_name_version_ext($answer_file);
 		    my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
                     my $getpropath = 1;
-		    my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,$domain,$stuname,$getpropath);
-		    my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
+                    my ($dir_list,$listerror) = 
+                        &Apache::lonnet::dirlist($portfolio_root.$portfolio_path,
+                                                 $domain,$stuname,$getpropath);
+		    my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
                     # fix file name
                     my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
                     my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
@@ -3067,8 +3069,10 @@
 		my ($answer_name,$answer_ver,$answer_ext) =
 		    &file_name_version_ext($answer_file);
                 my $getpropath = 1;    
-                my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,$stu_name,$getpropath);
-                my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
+                my ($dir_list,$listerror) = 
+                    &Apache::lonnet::dirlist($portfolio_root.$directory,$domain,
+                                             $stu_name,$getpropath);
+                my $version = &get_next_version($answer_name,$answer_ext,$dir_list);
                 my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
                 if ($new_answer ne 'problem getting file') {
                     push(@versioned_portfiles, $directory.$new_answer);
@@ -3087,21 +3091,24 @@
 sub get_next_version {
     my ($answer_name, $answer_ext, $dir_list) = @_;
     my $version;
-    foreach my $row (@$dir_list) {
-        my ($file) = split(/\&/,$row,2);
-        my ($file_name,$file_version,$file_ext) =
-	    &file_name_version_ext($file);
-        if (($file_name eq $answer_name) && 
-	    ($file_ext eq $answer_ext)) {
-                # gets here if filename and extension match, regardless of version
+    if (ref($dir_list) eq 'ARRAY') {
+        foreach my $row (@{$dir_list}) {
+            my ($file) = split(/\&/,$row,2);
+            my ($file_name,$file_version,$file_ext) =
+	        &file_name_version_ext($file);
+            if (($file_name eq $answer_name) && 
+	        ($file_ext eq $answer_ext)) {
+                     # gets here if filename and extension match, 
+                     # regardless of version
                 if ($file_version ne '') {
-                # a versioned file is found  so save it for later
-                if ($file_version > $version) {
-		    $version = $file_version;
-	        }
+                    # a versioned file is found  so save it for later
+                    if ($file_version > $version) {
+		        $version = $file_version;
+	            }
+                }
             }
         }
-    } 
+    }
     $version ++;
     return($version);
 }
@@ -4999,14 +5006,16 @@
     my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
     my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
     my $getpropath = 1;
-    my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
-                                       $getpropath);
+    my ($dirlist,$listerror) = &Apache::lonnet::dirlist('userfiles',$cdom,
+                                                        $cname,$getpropath);
     my @possiblenames;
-    foreach my $filename (sort(@files)) {
-	($filename)=split(/&/,$filename);
-	if ($filename!~/^scantron_orig_/) { next ; }
-	$filename=~s/^scantron_orig_//;
-	push(@possiblenames,$filename);
+    if (ref($dirlist) eq 'ARRAY') {
+        foreach my $filename (sort(@{$dirlist})) {
+	    ($filename)=split(/&/,$filename);
+	    if ($filename!~/^scantron_orig_/) { next ; }
+	    $filename=~s/^scantron_orig_//;
+	    push(@possiblenames,$filename);
+        }
     }
     return @possiblenames;
 }
Index: loncom/homework/essayresponse.pm
diff -u loncom/homework/essayresponse.pm:1.115 loncom/homework/essayresponse.pm:1.116
--- loncom/homework/essayresponse.pm:1.115	Tue Jul 26 17:14:51 2011
+++ loncom/homework/essayresponse.pm	Mon Oct 17 12:41:35 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # essay (ungraded) style responses
 #
-# $Id: essayresponse.pm,v 1.115 2011/07/26 17:14:51 raeburn Exp $
+# $Id: essayresponse.pm,v 1.116 2011/10/17 12:41:35 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -397,8 +397,11 @@
                 my ($path,$filename) = ($file =~ m{^(.*/)([^/]+)$});
                 my $fullpath = '/userfiles/portfolio'.$path;
                 if (!exists($dirlist{$fullpath})) {
-                    my @list = &Apache::lonnet::dirlist($fullpath,$udom,$uname,1);
-                    $dirlist{$fullpath} = \@list;
+                    my ($listref,$listerror) =
+                        &Apache::lonnet::dirlist($fullpath,$udom,$uname,1);
+                    if (ref($listref) eq 'ARRAY') {
+                        $dirlist{$fullpath} = $listref;
+                    }
                 }
                 if (ref($dirlist{$fullpath}) eq 'ARRAY') {
                     foreach my $dir_line (@{$dirlist{$fullpath}}) {
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1135 loncom/lonnet/perl/lonnet.pm:1.1136
--- loncom/lonnet/perl/lonnet.pm:1.1135	Sun Oct 16 14:24:39 2011
+++ loncom/lonnet/perl/lonnet.pm	Mon Oct 17 12:41:39 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1135 2011/10/16 14:24:39 raeburn Exp $
+# $Id: lonnet.pm,v 1.1136 2011/10/17 12:41:39 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -8250,7 +8250,9 @@
     if($udom) {
         if($uname) {
             my $uhome = &homeserver($uname,$udom);
-            return if ($uhome eq 'no_host'); 
+            if ($uhome eq 'no_host') {
+                return ([],'no_host');
+            }
             $listing = &reply('ls3:'.&escape('/'.$uri).':'.$getpropath.':'
                               .$getuserdir.':'.&escape($dirRoot)
                               .':'.&escape($uname).':'.&escape($udom),$uhome);
@@ -8266,12 +8268,14 @@
                 @listing_results = map { &unescape($_); } split(/:/,$listing);
             }
             if (($listing eq 'no_such_host') || ($listing eq 'con_lost') || 
-                ($listing eq 'rejected') || ($listing eq 'refused')) {
-                return;       
+                ($listing eq 'rejected') || ($listing eq 'refused') ||
+                ($listing eq 'no_such_dir') || ($listing eq 'empty')) {
+                return ([],$listing);
+            } else {
+                return (\@listing_results);
             }
-            return @listing_results;
         } elsif(!$alternateRoot) {
-            my %allusers;
+            my (%allusers,%listerror);
 	    my %servers = &get_servers($udom,'library');
  	    foreach my $tryserver (keys(%servers)) {
                 $listing = &reply('ls3:'.&escape("/res/$udom").':::::'.
@@ -8290,32 +8294,31 @@
 		    @listing_results =
 			map { &unescape($_); } split(/:/,$listing);
 		}
-		if ($listing_results[0] ne 'no_such_dir' && 
-		    $listing_results[0] ne 'empty'       &&
-		    $listing_results[0] ne 'con_lost') {
+                if (($listing eq 'no_such_host') || ($listing eq 'con_lost') ||
+                    ($listing eq 'rejected') || ($listing eq 'refused') ||
+                    ($listing eq 'no_such_dir') || ($listing eq 'empty')) {
+                    $listerror{$tryserver} = $listing;
+                } else {
 		    foreach my $line (@listing_results) {
 			my ($entry) = split(/&/,$line,2);
 			$allusers{$entry} = 1;
 		    }
 		}
             }
-            my $alluserstr='';
+            my @alluserslist=();
             foreach my $user (sort(keys(%allusers))) {
-                $alluserstr.=$user.'&user:';
+                push(@alluserslist,$user.'&user');
             }
-            $alluserstr=~s/:$//;
-            return split(/:/,$alluserstr);
+            return (\@alluserslist);
         } else {
-            return ('missing user name');
+            return ([],'missing username');
         }
     } elsif(!defined($getpropath)) {
-        my @all_domains = sort(&all_domains());
-        foreach my $domain (@all_domains) {
-            $domain = $perlvar{'lonDocRoot'}.'/res/'.$domain.'/&domain';
-        }
-        return @all_domains;
+        my $path = $perlvar{'lonDocRoot'}.'/res/'; 
+        my @all_domains = map { $path.$_.'/&domain'; } (sort(&all_domains()));
+        return (\@all_domains);
     } else {
-        return ('missing domain');
+        return ([],'missing domain');
     }
 }
 
@@ -8328,11 +8331,13 @@
     my ($studentDomain,$studentName,$filename,$getuserdir)=@_;
     $studentDomain = &LONCAPA::clean_domain($studentDomain);
     $studentName   = &LONCAPA::clean_username($studentName);
-    my ($fileStat) = 
-        &Apache::lonnet::dirlist($filename,$studentDomain,$studentName, 
-                                 undef,$getuserdir);
-    my @stats = split('&', $fileStat);
-    if($stats[0] ne 'empty' && $stats[0] ne 'no_such_dir') {
+    my ($fileref,$error) = &dirlist($filename,$studentDomain,$studentName,
+                                    undef,$getuserdir);
+    if (($error eq 'empty') || ($error eq 'no_such_dir')) {
+        return -1;
+    }
+    if (ref($fileref) eq 'ARRAY') {
+        my @stats = split('&',$fileref->[0]);
         # @stats contains first the filename, then the stat output
         return $stats[10]; # so this is 10 instead of 9.
     } else {
@@ -8364,12 +8369,15 @@
     if ($file =~ /^userfiles\//) {
         $getpropath = 1;
     }
-    my ($result) = &dirlist($file,$udom,$uname,$getpropath);
-    my @stats = split('&', $result);
-    
-    if($stats[0] ne 'empty' && $stats[0] ne 'no_such_dir') {
-	shift(@stats); #filename is first
-	return @stats;
+    my ($listref,$error) = &dirlist($file,$udom,$uname,$getpropath);
+    if (($error eq 'empty') || ($error eq 'no_such_dir')) {
+        return ();
+    } else {
+        if (ref($listref) eq 'ARRAY') {
+            my @stats = split('&',$listref->[0]);
+	    shift(@stats); #filename is first
+	    return @stats;
+        }
     }
     return ();
 }


More information about the LON-CAPA-cvs mailing list