index to temporary path and rename at at end [0.02]
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 11 Sep 2006 20:49:37 +0000 (20:49 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 11 Sep 2006 20:49:37 +0000 (20:49 +0000)
git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@673 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Output/EstraierNative.pm

index 50d60b1..055367f 100644 (file)
@@ -11,6 +11,7 @@ use Data::Dumper;
 use LWP;
 use URI::Escape;
 use List::Util qw/first/;
+use File::Path;
 
 $Estraier::DEBUG = 1;
 
@@ -21,11 +22,11 @@ WebPAC::Output::EstraierNative - Create Hyper Estraier full text index using nat
 
 =head1 VERSION
 
-Version 0.1
+Version 0.2
 
 =cut
 
-our $VERSION = '0.1';
+our $VERSION = '0.2';
 
 =head1 SYNOPSIS
 
@@ -92,6 +93,15 @@ sub new {
        $self->{label} ||= "WebPAC $self->{database}";
 
        my $path = 'casket';
+       $path =~ s!/+$!!;
+
+       $self->{_casket_path} = $path;
+
+       $path .= '.tmp';
+       if (-e $path) {
+               rmtree($path) || $log->logdie("can't remove old temporary directory $path: $!");
+       }
+       mkpath($path) || $log->logdie("can't create new temporary directory $path: $!");
 
        my $db = new Database();
        unless($db->open($path, Database::DBWRITER | Database::DBCREAT)) {
@@ -241,6 +251,34 @@ sub add_link {
 }
 
 
+=head2 finish
+
+Close index and rename of to final path
+
+       $est->finish;
+
+=cut
+
+sub finish {
+       my $self = shift;
+
+       my $log = $self->_get_logger;
+       $log->info("closing Hyper Estraier index make it current...");
+
+       $self->{db}->close || $log->logdie("can't close index");
+
+       my $path = $self->{_casket_path} || $log->logdie("no _casket_path?");
+
+       if (-e $path) {
+               $log->warn("removing old $path");
+               rmtree($path) || $log->logdie("can't remove old temporary directory $path: $!");
+       }
+
+       rename $path . '.tmp', $path || $log->logdie("can't rename ${path}.tmp -> $path: $!");
+
+}
+
+
 =head2 convert
 
  my $utf8_string = $self->convert('string in codepage');