--- loncom/lonnet/perl/lonnet.pm 2024/12/25 06:07:01 1.1531 +++ loncom/lonnet/perl/lonnet.pm 2024/12/27 02:32:55 1.1532 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.1531 2024/12/25 06:07:01 raeburn Exp $ +# $Id: lonnet.pm,v 1.1532 2024/12/27 02:32:55 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -12557,6 +12557,8 @@ sub stat_file { # $relpath - Current path (relative to top level). # $dirhashref - reference to hash to populate with URLs of directories (Required) # $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 # @@ -12569,7 +12571,8 @@ sub stat_file { # 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'); my $docroot = $perlvar{'lonDocRoot'}; my $currpath = $docroot.$toppath; @@ -12577,7 +12580,7 @@ sub recursedirs { $currpath .= "/$relpath"; } my ($savefile,$checkinc,$checkexc); - if (ref($filehashref)) { + if (ref($filehashref) eq 'HASH') { $savefile = 1; } if (ref($include) eq 'HASH') { @@ -12600,7 +12603,8 @@ sub recursedirs { } $dirhashref->{&Apache::lonlocal::js_escape($newpath)} = 1; 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 '')) { next if ($nonemptydir && $filecount); @@ -12617,10 +12621,16 @@ sub recursedirs { $dirhashref->{'/'} = 1; } if ($savefile) { + my $value; + if ($getlastmod) { + ($value) = (stat("$currpath/$item"))[9]; + } else { + $value = 1; + } if ($relpath eq '') { - $filehashref->{'/'}{$item} = 1; + $filehashref->{'/'}{$item} = $value } else { - $filehashref->{&Apache::lonlocal::js_escape($relpath)}{$item} = 1; + $filehashref->{&Apache::lonlocal::js_escape($relpath)}{$item} = $value; } } $filecount ++; @@ -12629,8 +12639,11 @@ sub recursedirs { closedir($dirh); } } else { - my ($dirlistref,$listerror) = - &dirlist($toppath.$relpath); + my $url = $toppath; + if ($relpath ne '') { + $url = $toppath.'/'.$relpath; + } + my ($dirlistref,$listerror) = &dirlist($url); my @dir_lines; my $dirptr=16384; if (ref($dirlistref) eq 'ARRAY') { @@ -12654,12 +12667,13 @@ sub recursedirs { } $dirhashref->{&Apache::lonlocal::js_escape($newpath)} = 1; 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 '')) { next if ($nonemptydir && $filecount); if ($checkinc || $checkexc) { - my $extension; + my ($extension) = ($item =~ /\.(\w+)$/); if ($checkinc) { next unless ($extension && $include->{$extension}); } @@ -12671,10 +12685,16 @@ sub recursedirs { $dirhashref->{'/'} = 1; } if ($savefile) { + my $value; + if ($getlastmod) { + $value = $mtime; + } else { + $value = 1; + } if ($relpath eq '') { - $filehashref->{'/'}{$item} = 1; + $filehashref->{'/'}{$item} = $value; } else { - $filehashref->{&Apache::lonlocal::js_escape($relpath)}{$item} = 1; + $filehashref->{&Apache::lonlocal::js_escape($relpath)}{$item} = $value; } } $filecount ++; @@ -12701,6 +12721,14 @@ sub priv_exclude { }; } +sub res_exclude { + return { + meta => 1, + subscription => 1, + rights => 1, + }; +} + # -------------------------------------------------------- Value of a Condition # gets the value of a specific preevaluated condition @@ -15170,6 +15198,49 @@ sub repcopy_userfile { 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=¤t_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 { my $uri=shift; $uri=~s|^https?\://([^/]+)||;