--- trunk/PlusPlus.pm 2004/12/05 14:35:54 13 +++ trunk/PlusPlus.pm 2004/12/05 15:35:53 14 @@ -92,8 +92,11 @@ my $index_dir = $self->{'index_dir'}; + my $cwd; + chomp($cwd = `pwd`); + $self->{'cwd'} = $cwd || carp "can't get cwd!"; + if ($index_dir !~ m#^/#) { - chomp(my $cwd = `pwd`); $index_dir = "$cwd/$index_dir"; print STDERR "## full path to index_dir: $index_dir\n" if ($self->{'debug'}); $self->{'index_dir'} = $index_dir; @@ -143,6 +146,7 @@ confess $self->{'search'}," binary is not SWISH++" unless ($s =~ m/^SWISH\+\+/); if ($i eq $s) { + $i =~ s/^SWISH\+\+\s+// || confess "can't strip SWISH++ from version"; $self->{'version'} = $i; return 1; } else { @@ -217,7 +221,7 @@ my $query = shift || return; - $self->_close_index; + $self->finish_update; my @results; @@ -261,6 +265,8 @@ sub finish_update { my $self = shift; + print STDERR "## finish_update\n" if ($self->{'debug'}); + $self->_close_index; } @@ -289,9 +295,14 @@ sub _init_indexer { my $self = shift; - $self->{'tmp_dir'} = tempdir( CLEANUP => 1 ) || confess "can't create temporary directory: $!"; + return if ($self->{'_index_fh'}); - chdir $self->{'tmp_dir'} || confess "can't chdir to ".$self->{'tmp_dir'}.": $!"; + my $tmp_dir = tempdir( CLEANUP => 1 ) || confess "can't create temporary directory: $!"; + $self->{'tmp_dir'} = $tmp_dir; + + chdir $tmp_dir || confess "can't chdir to ".$tmp_dir.": $!"; + + print STDERR "## tmp_dir: $tmp_dir" if ($self->{'debug'}); my $opt = "-v " . ($self->{'debug'} || '0'); @@ -304,12 +315,13 @@ my $open_cmd = '| '.$self->{'index'}.' '.$opt.' -e "html:*" -i '.$self->{'index_dir'}.'/index -'; - print STDERR "## open index $open_cmd\n" if ($self->{'index'}); + print STDERR "## init_indexer: $open_cmd\n" if ($self->{'debug'}); - open($self->{'index_fh'}, $open_cmd) || confess "can't start index with $open_cmd: $!"; + open($self->{'_index_fh'}, $open_cmd) || confess "can't start index with $open_cmd: $!"; + chdir $self->{'cwd'} || confess "can't chdir to ".$self->{'cwd'}.": $!"; - return $self->{'index_fh'}; + return $self->{'_index_fh'}; } =head2 _create_doc @@ -336,11 +348,14 @@ my $arg = {@_}; # open indexer if needed - $self->{'index_fh'} ||= $self->_init_indexer; + $self->_init_indexer; my $path = $self->{'tmp_dir'} || confess "no tmp_dir?"; + $path .= '/' . $arg->{'path'}; + + print STDERR "## _create_doc: $path\n" if ($self->{'debug'}); - open(TMP, '>', $arg->{'path'}) || die "can't create temp file ".$arg->{'path'}.": $!"; + open(TMP, '>', $path) || die "can't create temp file $path: $!"; print TMP ''; @@ -363,7 +378,7 @@ close(TMP) || confess "can't close tmp file ".$arg->{'path'}.": $!"; - print { $self->{'index_fh'} } $arg->{'path'}."\n"; + print { $self->{'_index_fh'} } $arg->{'path'}."\n"; } =head2 _close_index @@ -379,12 +394,12 @@ sub _close_index { my $self = shift; - return unless ($self->{'index_fh'}); + return unless ($self->{'_index_fh'}); print STDERR "## close index\n" if ($self->{'debug'}); - close($self->{'index_fh'}); - undef $self->{'index_fh'}; + close($self->{'_index_fh'}); + undef $self->{'_index_fh'}; } 1;