--- loncom/interface/lonindexer.pm 2003/02/20 19:41:26 1.61 +++ loncom/interface/lonindexer.pm 2003/06/16 22:09:02 1.68 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Directory Indexer # -# $Id: lonindexer.pm,v 1.61 2003/02/20 19:41:26 www Exp $ +# $Id: lonindexer.pm,v 1.68 2003/06/16 22:09:02 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -84,13 +84,13 @@ my @Omit = (); # ----------------------------- Handling routine called via Apache and mod_perl sub handler { my $r = shift; + my $c = $r->connection(); $r->content_type('text/html'); &Apache::loncommon::no_cache($r); $r->send_http_header; return OK if $r->header_only; $fnum=0; $dnum=0; - untie %hash; # Deal with stupid global variables (is there a way around making # these global to this package? It is just so wrong....) @@ -124,9 +124,18 @@ sub handler { $extrafield=''; my $diropendb = - "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db"; - - if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) { + "/home/httpd/perl/tmp/$ENV{'user.domain'}_$ENV{'user.name'}_indexer.db"; + %hash = (); + { + my %dbfile; + if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) { + while(my($key,$value)=each(%dbfile)) { + $hash{$key}=$value; + } + untie(%dbfile); + } + } + { if ($ENV{'form.launch'} eq '1') { &start_fresh_session(); } @@ -390,11 +399,12 @@ $r->print(&Apache::loncommon::bodytag('B Size Last access Last modified - Show Resource + All versions Author Keywords Language - All versions + Show Resource +  @@ -428,7 +438,7 @@ END $r->print("Language\n") if ($hash{'display_attrs_6'} == 1); $r->print("Resource\n") - if ($hash{'display_attrs_8'} == 1); + if ($hash{'display_attrs_7'} == 1); $r->print(''); # ----------------- read in what directories have previously been set to "open" @@ -492,18 +502,28 @@ END # --------------------------------------------------- end the output and return $r->print(''."\n"); - untie(%hash); - } else { - $r->print('Unable to tie hash to db '. - 'file'); - return OK; +# } else { +# $r->print('Unable to tie hash to db '. +# 'file'); +# return OK; + } + if(! $c->aborted()) { + my %dbfile; + if (tie(%dbfile,'GDBM_File',$diropendb,&GDBM_NEWDB(),0640)) { + while (my($key,$value) = each(%hash)) { + $dbfile{$key}=$value; + } + untie(%dbfile); + } } + return OK; } # ----------------------------------------------- recursive scan of a directory sub scanDir { my ($r,$startdir,$indent,$hashref)=@_; + my $c = $r->connection(); my ($compuri,$curdir); my $dirptr=16384; $indent++; @@ -511,15 +531,16 @@ sub scanDir { my %dupdirs = %dirs; my @list=&get_list($r,$startdir); foreach my $line (@list) { + return if ($c->aborted()); my ($strip,$dom,undef,$testdir,undef)=split(/\&/,$line,5); next if $strip =~ /.*\.meta$/; my (@fileparts) = split(/\./,$strip); - if ($hash{'display_attrs_7'} != 1) { + if ($hash{'display_attrs_8'} != 1) { if (scalar(@fileparts) >= 3) { my $fext = pop @fileparts; my $ov = pop @fileparts; my $fname = join ('.',@fileparts,$fext); - next if (grep /$fname/,@list and $ov =~ /\d+/); + next if (grep /\Q$fname\E/,@list and $ov =~ /\d+/); } } @@ -638,16 +659,18 @@ sub display_line { my $tabtag=''; my $i=0; - while ($i<=6) { + while ($i<=7) { $tabtag=join('',$tabtag," ") if $hash{'display_attrs_'.$i} == 1; $i++; } + + my $valign = ($hash{'display_attrs_7'} == 1 ? 'top' : 'bottom'); # display uplink arrow if ($filecom[1] eq 'viewOneUp') { $r->print("$extrafield"); - $r->print("\n"); + $r->print("\n"); $r->print ('
\n"); return OK; } +# Do we have permission to look at this? + + return OK if (!&Apache::lonnet::allowed('bre',$startdir.$filecom[0])); # display domain if ($filecom[1] eq 'domain') { $r->print (''."\n") if ($ENV{'form.dirPointer'} eq "on"); $r->print("$extrafield"); - $r->print(""); + $r->print(""); &begin_form ($r,$filecom[0].'/'); my $anchor = $filecom[0].'/'; $anchor =~ s/\///g; @@ -694,7 +720,7 @@ sub display_line { } if ($filecom[1] eq 'user') { $r->print("$extrafield"); - $r->print("\n"); + $r->print("\n"); my $curdir = $startdir.$filecom[0].'/'; my $anchor = $curdir; $anchor =~ s/\///g; @@ -720,7 +746,6 @@ sub display_line { # display file if ($fnptr == 0 and $filecom[3] ne '') { my $filelink = $startdir.$filecom[0]; - return OK if (!&Apache::lonnet::allowed('bre',$filelink)); my @file_ext = split (/\./,$listname); my $curfext = $file_ext[-1]; if (@Omit) { @@ -738,8 +763,8 @@ sub display_line { $iconname = $curfext.".gif" unless (!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn'); # - $r->print(""); - my $metafile = grep /^$filecom[0]\.meta\&/, @list; + $r->print(""); + my $metafile = grep /^\Q$filecom[0]\E\.meta\&/, @list; my $title; if ($ENV{'form.catalogmode'} eq 'interactive') { $title=$listname; @@ -752,7 +777,7 @@ sub display_line { $titleesc,"','",$filelink,"')\">"); $r->print("". "\n"); - $r->print(""); + $r->print(""); } elsif ($ENV{'form.catalogmode'} eq 'groupimport') { $title=$listname; @@ -771,7 +796,7 @@ sub display_line { $r->print("\n"); $r->print("\n"); - $r->print(""); + $r->print(""); $hash{"pre_${fnum}_link"}=$filelink; $hash{"pre_${fnum}_title"}=$titleesc; $fnum++; @@ -806,40 +831,40 @@ sub display_line { if ($hash{'display_attrs_0'} == 1) { my $title = &Apache::lonnet::metadata($filelink,'title') if ($metafile == 1); - $r->print(' '.($title eq '' ? ' ' : $title). + $r->print(' '.($title eq '' ? ' ' : $title). ' '."\n"); } - $r->print(' ', + $r->print(' ', $filecom[8]," \n") if $hash{'display_attrs_1'} == 1; - $r->print(' '. + $r->print(' '. (localtime($filecom[9]))." \n") if $hash{'display_attrs_2'} == 1; - $r->print(' '. + $r->print(' '. (localtime($filecom[10]))." \n") if $hash{'display_attrs_3'} == 1; if ($hash{'display_attrs_4'} == 1) { my $author = &Apache::lonnet::metadata($filelink,'author') if ($metafile == 1); - $r->print(' '.($author eq '' ? ' ' : $author). + $r->print(' '.($author eq '' ? ' ' : $author). " \n"); } if ($hash{'display_attrs_5'} == 1) { my $keywords = &Apache::lonnet::metadata($filelink,'keywords') if ($metafile == 1); # $keywords = ' ' if (!$keywords); - $r->print(' '.($keywords eq '' ? ' ' : $keywords). + $r->print(' '.($keywords eq '' ? ' ' : $keywords). " \n"); } if ($hash{'display_attrs_6'} == 1) { my $lang = &Apache::lonnet::metadata($filelink,'language') if ($metafile == 1); $lang = &Apache::loncommon::languagedescription($lang); - $r->print(' '.($lang eq '' ? ' ' : $lang). + $r->print(' '.($lang eq '' ? ' ' : $lang). " \n"); } - if ($hash{'display_attrs_8'} == 1) { + if ($hash{'display_attrs_7'} == 1) { my $output=''; my $embstyle=&Apache::loncommon::fileembstyle($curfext); if ($embstyle eq 'ssi') { @@ -852,7 +877,7 @@ sub display_line { $Apache::lonnet::hostname{&Apache::lonnet::homeserver($2,$1)}. '/cgi-bin/thumbnail.gif?url='.$filelink.'" />'; } - $r->print(' '.($output eq '' ? ' ':$output). + $r->print(' '.($output eq '' ? ' ':$output). " \n"); } $r->print("\n"); @@ -865,7 +890,7 @@ sub display_line { my $curdir = $startdir.$filecom[0].'/'; my $anchor = $curdir; $anchor =~ s/\///g; - $r->print("$extrafield"); + $r->print("$extrafield"); &begin_form ($r,$curdir); my $indentm1 = $indent-1; if ($indentm1 < 11 and $indentm1 > 0) { @@ -943,9 +968,6 @@ sub setvalues { sub cleanup { if (tied(%hash)){ &Apache::lonnet::logthis('Cleanup indexer: hash'); - unless (untie(%hash)) { - &Apache::lonnet::logthis('Failed cleanup indexer: hash'); - } } }