--- loncom/lonnet/perl/lonnet.pm 2023/03/19 16:05:48 1.1504 +++ loncom/lonnet/perl/lonnet.pm 2023/03/27 18:41:07 1.1505 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.1504 2023/03/19 16:05:48 raeburn Exp $ +# $Id: lonnet.pm,v 1.1505 2023/03/27 18:41:07 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -12105,6 +12105,7 @@ sub stat_file { # 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). +# $addtopdir - if true, set $dirhashref->{'/'} = 1 # $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) @@ -12121,7 +12122,7 @@ sub stat_file { # sub recursedirs { - my ($is_home,$recurse,$include,$exclude,$nonemptydir,$toppath,$relpath,$dirhashref,$filehashref) = @_; + my ($is_home,$recurse,$include,$exclude,$nonemptydir,$addtopdir,$toppath,$relpath,$dirhashref,$filehashref) = @_; return unless (ref($dirhashref) eq 'HASH'); my $docroot = $perlvar{'lonDocRoot'}; my $currpath = $docroot.$toppath; @@ -12139,7 +12140,7 @@ sub recursedirs { $checkexc = 1; } if ($is_home) { - if (opendir(my $dirh,$currpath)) { + if ((-e $currpath) && (opendir(my $dirh,$currpath))) { my $filecount = 0; foreach my $item (sort { lc($a) cmp lc($b) } grep(!/^\.+$/,readdir($dirh))) { next if ($item eq ''); @@ -12152,7 +12153,7 @@ sub recursedirs { } $dirhashref->{&Apache::lonlocal::js_escape($newpath)} = 1; if ($recurse) { - &recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,$toppath,$newpath,$dirhashref,$filehashref); + &recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,$addtopdir,$toppath,$newpath,$dirhashref,$filehashref); } } elsif (($savefile) || ($relpath eq '')) { next if ($nonemptydir && $filecount); @@ -12165,7 +12166,7 @@ sub recursedirs { next if ($extension && $exclude->{$extension}); } } - if (($relpath eq '') && (!exists($dirhashref->{'/'}))) { + if (($relpath eq '') && (!exists($dirhashref->{'/'}))) { $dirhashref->{'/'} = 1; } if ($savefile) { @@ -12206,7 +12207,7 @@ sub recursedirs { } $dirhashref->{&Apache::lonlocal::js_escape($newpath)} = 1; if ($recurse) { - &recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,$toppath,$newpath,$dirhashref,$filehashref); + &recursedirs($is_home,$recurse,$include,$exclude,$nonemptydir,$addtopdir,$toppath,$newpath,$dirhashref,$filehashref); } } elsif (($savefile) || ($relpath eq '')) { next if ($nonemptydir && $filecount); @@ -12234,6 +12235,11 @@ sub recursedirs { } } } + if ($addtopdir) { + if (($relpath eq '') && (!exists($dirhashref->{'/'}))) { + $dirhashref->{'/'} = 1; + } + } return; }