Diff for /loncom/lonnet/perl/lonnet.pm between versions 1.1531 and 1.1532

version 1.1531, 2024/12/25 06:07:01 version 1.1532, 2024/12/27 02:32:55
Line 12557  sub stat_file { Line 12557  sub stat_file {
 # $relpath - Current path (relative to top level).  # $relpath - Current path (relative to top level).
 # $dirhashref - reference to hash to populate with URLs of directories (Required)  # $dirhashref - reference to hash to populate with URLs of directories (Required)
 # $filehashref - reference to hash to populate with URLs of files (Optional)  # $filehashref - reference to hash to populate with URLs of files (Optional)
   # $getlastmod - if true, will set value for each key in innerhash in $filehashref
   #               to last modification time of file; value set to 1 otherwise.
 #  #
 # Returns: nothing  # Returns: nothing
 #  #
Line 12569  sub stat_file { Line 12571  sub stat_file {
 #  #
   
 sub recursedirs {  sub recursedirs {
     my ($is_home,$recurse,$include,$exclude,$nonemptydir,$addtopdir,$toppath,$relpath,$dirhashref,$filehashref) = @_;      my ($is_home,$recurse,$include,$exclude,$nonemptydir,$addtopdir,$toppath,
           $relpath,$dirhashref,$filehashref,$getlastmod) = @_;
     return unless (ref($dirhashref) eq 'HASH');      return unless (ref($dirhashref) eq 'HASH');
     my $docroot = $perlvar{'lonDocRoot'};      my $docroot = $perlvar{'lonDocRoot'};
     my $currpath = $docroot.$toppath;      my $currpath = $docroot.$toppath;
Line 12577  sub recursedirs { Line 12580  sub recursedirs {
         $currpath .= "/$relpath";          $currpath .= "/$relpath";
     }      }
     my ($savefile,$checkinc,$checkexc);      my ($savefile,$checkinc,$checkexc);
     if (ref($filehashref)) {      if (ref($filehashref) eq 'HASH') {
         $savefile = 1;          $savefile = 1;
     }      }
     if (ref($include) eq 'HASH') {      if (ref($include) eq 'HASH') {
Line 12600  sub recursedirs { Line 12603  sub recursedirs {
                     }                      }
                     $dirhashref->{&Apache::lonlocal::js_escape($newpath)} = 1;                      $dirhashref->{&Apache::lonlocal::js_escape($newpath)} = 1;
                     if ($recurse) {                      if ($recurse) {
                         &recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,$addtopdir,$toppath,$newpath,$dirhashref,$filehashref);                          &recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,$addtopdir,
                                        $toppath,$newpath,$dirhashref,$filehashref,$getlastmod);
                     }                      }
                 } elsif (($savefile) || ($relpath eq '')) {                  } elsif (($savefile) || ($relpath eq '')) {
                     next if ($nonemptydir && $filecount);                      next if ($nonemptydir && $filecount);
Line 12617  sub recursedirs { Line 12621  sub recursedirs {
                         $dirhashref->{'/'} = 1;                          $dirhashref->{'/'} = 1;
                     }                      }
                     if ($savefile) {                      if ($savefile) {
                           my $value;
                           if ($getlastmod) {
                               ($value) = (stat("$currpath/$item"))[9];
                           } else {
                               $value = 1;
                           }
                         if ($relpath eq '') {                          if ($relpath eq '') {
                             $filehashref->{'/'}{$item} = 1;                              $filehashref->{'/'}{$item} = $value
                         } else {                          } else {
                             $filehashref->{&Apache::lonlocal::js_escape($relpath)}{$item} = 1;                              $filehashref->{&Apache::lonlocal::js_escape($relpath)}{$item} = $value;
                         }                          }
                     }                      }
                     $filecount ++;                      $filecount ++;
Line 12629  sub recursedirs { Line 12639  sub recursedirs {
             closedir($dirh);              closedir($dirh);
         }          }
     } else {      } else {
         my ($dirlistref,$listerror) =          my $url = $toppath;
             &dirlist($toppath.$relpath);          if ($relpath ne '') {
               $url = $toppath.'/'.$relpath;
           }
           my ($dirlistref,$listerror) = &dirlist($url);
         my @dir_lines;          my @dir_lines;
         my $dirptr=16384;          my $dirptr=16384;
         if (ref($dirlistref) eq 'ARRAY') {          if (ref($dirlistref) eq 'ARRAY') {
Line 12654  sub recursedirs { Line 12667  sub recursedirs {
                     }                      }
                     $dirhashref->{&Apache::lonlocal::js_escape($newpath)} = 1;                      $dirhashref->{&Apache::lonlocal::js_escape($newpath)} = 1;
                     if ($recurse) {                      if ($recurse) {
                         &recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,$addtopdir,$toppath,$newpath,$dirhashref,$filehashref);                          &recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,$addtopdir,
                                        $toppath,$newpath,$dirhashref,$filehashref,$getlastmod);
                     }                      }
                 } elsif (($savefile) || ($relpath eq '')) {                  } elsif (($savefile) || ($relpath eq '')) {
                     next if ($nonemptydir && $filecount);                      next if ($nonemptydir && $filecount);
                     if ($checkinc || $checkexc) {                      if ($checkinc || $checkexc) {
                         my $extension;                          my ($extension) = ($item =~ /\.(\w+)$/);
                         if ($checkinc) {                          if ($checkinc) {
                             next unless ($extension && $include->{$extension});                              next unless ($extension && $include->{$extension});
                         }                          }
Line 12671  sub recursedirs { Line 12685  sub recursedirs {
                         $dirhashref->{'/'} = 1;                          $dirhashref->{'/'} = 1;
                     }                      }
                     if ($savefile) {                      if ($savefile) {
                           my $value;
                           if ($getlastmod) {
                               $value = $mtime;
                           } else {
                               $value = 1;
                           }
                         if ($relpath eq '') {                          if ($relpath eq '') {
                             $filehashref->{'/'}{$item} = 1;                              $filehashref->{'/'}{$item} = $value;
                         } else {                          } else {
                             $filehashref->{&Apache::lonlocal::js_escape($relpath)}{$item} = 1;                              $filehashref->{&Apache::lonlocal::js_escape($relpath)}{$item} = $value;
                         }                          }
                     }                      }
                     $filecount ++;                       $filecount ++; 
Line 12701  sub priv_exclude { Line 12721  sub priv_exclude {
            };             };
 }  }
   
   sub res_exclude {
       return {
                meta => 1,
                subscription => 1,
                rights => 1,
              };
   }
   
 # -------------------------------------------------------- Value of a Condition  # -------------------------------------------------------- Value of a Condition
   
 # gets the value of a specific preevaluated condition  # gets the value of a specific preevaluated condition
Line 15170  sub repcopy_userfile { Line 15198  sub repcopy_userfile {
     return 'ok';      return 'ok';
 }  }
   
   sub repcopy_crsprivfile {
       my ($src,$dest) = @_;
       my $result;
       if ($src =~ m{^/priv/($match_domain)/($match_courseid)/(.+)$}) {
           my ($cdom,$cnum,$filepath) = ($1,$2,$3);
           $filepath =~ s/\.{2,}//g;
           my $chome = &homeserver($cnum,$cdom);
           unless ($chome eq 'no_host') {
               my @ids=&current_machine_ids();
               unless (grep(/^\Q$chome\E$/,@ids)) {
                   if (&is_course($cdom,$cnum)) {
                       my $londocroot = $perlvar{'lonDocRoot'};
                       if ($dest =~ m{^\Q$londocroot/priv/\E$match_domain/$match_username/.*\Q$filepath\E$}) {
                           my $cmd = 'crsfilefrompriv:'.&escape($filepath).':'.&escape($cnum).':'.&escape($cdom);
                           $result = &reply($cmd,$chome);
                           unless (($result eq 'unknown_cmd') || ($result =~ /^error:/)) {
                               my $url = &unescape($result);
                               if ($url =~ m{^https?://[^/]+\Q/userfiles/$cdom/$cnum/priv/$filepath\E$}) {
                                   my $request=new HTTP::Request('GET',$url);
                                   my $response=&LONCAPA::LWPReq::makerequest($chome,$request,'',\%perlvar,1200,1);
                                   if ($response->is_error()) {
                                       $result = 'error: '.$response->status_line;
                                   } else {
                                       if (open(my $fh,'>',$dest)) {
                                           print $fh $response->content;
                                           close($fh);
                                           $result = 'ok';
                                       } else {
                                           $result = 'error: nowrite';
                                       }
                                   }
                               } else {
                                   $result = 'error: invalidurl';
                               }
                           }
                       }
                   }
               }
           }
       }
       return $result;
   }
   
 sub tokenwrapper {  sub tokenwrapper {
     my $uri=shift;      my $uri=shift;
     $uri=~s|^https?\://([^/]+)||;      $uri=~s|^https?\://([^/]+)||;

Removed from v.1.1531  
changed lines
  Added in v.1.1532


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>