--- loncom/lonnet/perl/lonnet.pm 2022/10/19 00:03:11 1.1496 +++ loncom/lonnet/perl/lonnet.pm 2022/12/31 14:09:00 1.1503 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.1496 2022/10/19 00:03:11 raeburn Exp $ +# $Id: lonnet.pm,v 1.1503 2022/12/31 14:09:00 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -2924,6 +2924,7 @@ sub get_dom_instcats { if (&auto_instcode_format($caller,$dom,\%coursecodes,\%codes, \@codetitles,\%cat_titles,\%cat_order) eq 'ok') { $instcats = { + totcodes => $totcodes, codes => \%codes, codetitles => \@codetitles, cat_titles => \%cat_titles, @@ -10333,7 +10334,7 @@ sub assignrole { if ($role =~ /^cr\//) { my $cwosec=$url; $cwosec=~s/^\/($match_domain)\/($match_courseid)\/.*/$1\/$2/; - unless (&allowed('ccr',$cwosec)) { + if ((!&allowed('ccr',$cwosec)) && (!&allowed('ccr',$udom))) { my $refused = 1; if ($context eq 'requestcourses') { if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) { @@ -12025,14 +12026,19 @@ sub stat_file { # or corresponding Published Resource Space, and populate the hash ref: # $dirhashref with URLs of all directories, and if $filehashref hash # ref arg is provided, the URLs of any files, excluding versioned, .meta, -# or .rights files in resource space, and .meta, .save, .log, and .bak -# files in Authoring Space. +# or .rights files in resource space, and .meta, .save, .log, .bak and +# .rights files in Authoring Space. # # Inputs: # # $is_home - true if current server is home server for user's space -# $context - either: priv, or res respectively for Authoring or Resource Space. -# $docroot - Document root (i.e., /home/httpd/html +# $recurse - if true will also traverse subdirectories recursively +# $include - reference to hash containing allowed file extensions. If provided, +# files which do not have a matching extension will be ignored. +# $exclude - reference to hash containing excluded file extensions. If provided, +# files which have a matching extension will be ignored. +# $nonemptydir - if true, will only populate $fileshashref hash entry for a particular +# directory with first file found (with acceptable extension). # $toppath - Top level directory (i.e., /res/$dom/$uname or /priv/$dom/$uname # $relpath - Current path (relative to top level). # $dirhashref - reference to hash to populate with URLs of directories (Required) @@ -12049,39 +12055,61 @@ sub stat_file { # sub recursedirs { - my ($is_home,$context,$docroot,$toppath,$relpath,$dirhashref,$filehashref) = @_; + my ($is_home,$recurse,$include,$exclude,$nonemptydir,$toppath,$relpath,$dirhashref,$filehashref) = @_; return unless (ref($dirhashref) eq 'HASH'); + my $docroot = $perlvar{'lonDocRoot'}; my $currpath = $docroot.$toppath; - if ($relpath) { + if ($relpath ne '') { $currpath .= "/$relpath"; } - my $savefile; + my ($savefile,$checkinc,$checkexc); if (ref($filehashref)) { $savefile = 1; } + if (ref($include) eq 'HASH') { + $checkinc = 1; + } + if (ref($exclude) eq 'HASH') { + $checkexc = 1; + } if ($is_home) { if (opendir(my $dirh,$currpath)) { + my $filecount = 0; foreach my $item (sort { lc($a) cmp lc($b) } grep(!/^\.+$/,readdir($dirh))) { next if ($item eq ''); if (-d "$currpath/$item") { my $newpath; - if ($relpath) { + if ($relpath ne '') { $newpath = "$relpath/$item"; } else { $newpath = $item; } $dirhashref->{&Apache::lonlocal::js_escape($newpath)} = 1; - &recursedirs($is_home,$context,$docroot,$toppath,$newpath,$dirhashref,$filehashref); - } elsif ($savefile) { - if ($context eq 'priv') { - unless ($item =~ /\.(meta|save|log|bak|DS_Store)$/) { - $filehashref->{&Apache::lonlocal::js_escape($relpath)}{$item} = 1; - } - } else { - unless (($item =~ /\.meta$/) || ($item =~ /\.\d+\.\w+$/) || ($item =~ /\.rights$/)) { + if ($recurse) { + &recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,$toppath,$newpath,$dirhashref,$filehashref); + } + } elsif (($savefile) || ($relpath eq '')) { + next if ($nonemptydir && $filecount); + if ($checkinc || $checkexc) { + my ($extension) = ($item =~ /\.(\w+)$/); + if ($checkinc) { + next unless ($extension && $include->{$extension}); + } + if ($checkexc) { + next if ($extension && $exclude->{$extension}); + } + } + if (($relpath eq '') && (!exists($dirhashref->{'/'}))) { + $dirhashref->{'/'} = 1; + } + if ($savefile) { + if ($relpath eq '') { + $filehashref->{'/'}{$item} = 1; + } else { $filehashref->{&Apache::lonlocal::js_escape($relpath)}{$item} = 1; } } + $filecount ++; } } closedir($dirh); @@ -12092,6 +12120,7 @@ sub recursedirs { my @dir_lines; my $dirptr=16384; if (ref($dirlistref) eq 'ARRAY') { + my $filecount = 0; foreach my $dir_line (sort { my ($afile)=split('&',$a,2); @@ -12107,21 +12136,34 @@ sub recursedirs { if ($relpath) { $newpath = "$relpath/$item"; } else { - $relpath = '/'; $newpath = $item; } $dirhashref->{&Apache::lonlocal::js_escape($newpath)} = 1; - &recursedirs($is_home,$context,$docroot,$toppath,$newpath,$dirhashref,$filehashref); - } elsif ($savefile) { - if ($context eq 'priv') { - unless ($item =~ /\.(meta|save|log|bak|DS_Store)$/) { - $filehashref->{$relpath}{$item} = 1; - } - } else { - unless (($item =~ /\.meta$/) || ($item =~ /\.\d+\.\w+$/)) { - $filehashref->{$relpath}{$item} = 1; + if ($recurse) { + &recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,$toppath,$newpath,$dirhashref,$filehashref); + } + } elsif (($savefile) || ($relpath eq '')) { + next if ($nonemptydir && $filecount); + if ($checkinc || $checkexc) { + my $extension; + if ($checkinc) { + next unless ($extension && $include->{$extension}); + } + if ($checkexc) { + next if ($extension && $exclude->{$extension}); + } + } + if (($relpath eq '') && (!exists($dirhashref->{'/'}))) { + $dirhashref->{'/'} = 1; + } + if ($savefile) { + if ($relpath eq '') { + $filehashref->{'/'}{$item} = 1; + } else { + $filehashref->{&Apache::lonlocal::js_escape($relpath)}{$item} = 1; } } + $filecount ++; } } } @@ -12129,6 +12171,17 @@ sub recursedirs { return; } +sub priv_exclude { + return { + meta => 1, + save => 1, + log => 1, + bak => 1, + rights => 1, + DS_Store => 1, + }; +} + # -------------------------------------------------------- Value of a Condition # gets the value of a specific preevaluated condition @@ -12468,7 +12521,7 @@ sub count_supptools { my $chome=&homeserver($cnum,$cdom); $numexttools = 0; unless ($chome eq 'no_host') { - my ($supplemental) = &get_supplemental($cnum,$cdom,$reload); + my ($supplemental) = &Apache::loncommon::get_supplemental($cnum,$cdom,$reload); if (ref($supplemental) eq 'HASH') { if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) { foreach my $key (keys(%{$supplemental->{'ids'}})) { @@ -12485,7 +12538,7 @@ sub count_supptools { } sub has_unhidden_suppfiles { - my ($cnum,$cdom,$ignorecache)=@_; + my ($cnum,$cdom,$ignorecache,$possdel)=@_; my $hashid=$cnum.':'.$cdom; my ($showsupp,$cached); unless ($ignorecache) { @@ -12494,7 +12547,7 @@ sub has_unhidden_suppfiles { unless (defined($cached)) { my $chome=&homeserver($cnum,$cdom); unless ($chome eq 'no_host') { - my ($supplemental) = &get_supplemental($cnum,$cdom,$ignorecache); + my ($supplemental) = &Apache::loncommon::get_supplemental($cnum,$cdom,$ignorecache,$possdel); if (ref($supplemental) eq 'HASH') { if ((ref($supplemental->{'ids'}) eq 'HASH') && (ref($supplemental->{'hidden'}) eq 'HASH')) { foreach my $key (keys(%{$supplemental->{'ids'}})) { @@ -12517,35 +12570,6 @@ sub has_unhidden_suppfiles { return $showsupp; } -sub get_supplemental { - my ($cnum,$cdom,$ignorecache,$possdel)=@_; - my $hashid=$cnum.':'.$cdom; - my ($supplemental,$cached,$set_httprefs); - unless ($ignorecache) { - ($supplemental,$cached) = &is_cached_new('supplemental',$hashid); - } - unless (defined($cached)) { - my $chome=&homeserver($cnum,$cdom); - unless ($chome eq 'no_host') { - my ($errors,%ids,%hidden); - $errors = - &Apache::loncommon::recurse_supplemental($cnum,$cdom, - 'supplemental.sequence', - $errors,$possdel,\%ids,\%hidden); - $set_httprefs = 1; - if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { - &Apache::lonnet::appenv({'request.course.suppupdated' => time}); - } - $supplemental = { - ids => \%ids, - hidden => \%hidden, - }; - &do_cache_new('supplemental',$hashid,$supplemental,600); - } - } - return ($supplemental,$set_httprefs); -} - # # EXT resource caching routines # @@ -13710,6 +13734,29 @@ sub devalidate_suppchange_cache { &devalidate_cache_new('suppchange',$hashid); } +sub update_supp_caches { + my ($cdom,$cnum) = @_; + my %servers = &internet_dom_servers($cdom); + my @ids=¤t_machine_ids(); + foreach my $server (keys(%servers)) { + next if (grep(/^\Q$server\E$/,@ids)); + my $hashid=$cnum.':'.$cdom; + my $cachekey = &escape('showsupp').':'.&escape($hashid); + &remote_devalidate_cache($server,[$cachekey]); + } + &has_unhidden_suppfiles($cnum,$cdom,1,1); + &count_supptools($cnum,$cdom,1); + my $now = time; + if ($env{'request.course.id'} eq $cdom.'_'.$cnum) { + &Apache::lonnet::appenv({'request.course.suppupdated' => $now}); + } + &put('environment',{'internal.supplementalchange' => $now}, + $cdom,$cnum); + &Apache::lonnet::appenv( + {'course.'.$cdom.'_'.$cnum.'.internal.supplementalchange' => $now}); + &do_cache_new('suppchange',$cdom.'_'.$cnum,$now,600); +} + # ------------------------------------------------- Update symbolic store links sub symblist {