added EST_SYNC_EVERY => 10000 to sync HyperEstraier database every 10000
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Tue, 30 Aug 2005 09:55:55 +0000 (09:55 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Tue, 30 Aug 2005 09:55:55 +0000 (09:55 +0000)
entries. Catching SIGINT and SIGQUIT and sync HyperEstraier database.

git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@97 8392b6e1-25fa-0310-8288-cc32f8e212ea

bin/BackupPC_updatedb

index e433555..a3d0dff 100755 (executable)
@@ -13,6 +13,7 @@ use File::Pid;
 use POSIX qw/strftime/;
 
 use constant BPC_FTYPE_DIR => 5;
+use constant EST_SYNC_EVERY => 10000;
 
 my $debug = 0;
 $|=1;
@@ -85,6 +86,19 @@ sub curr_time {
 
 my $hest_db;
 
+sub signal {
+       my($sig) = @_;
+       if ($hest_db) {
+               print "\nCaught a SIG$sig--syncing database and shutting down\n";
+               $hest_db->sync();
+               $hest_db->close();
+       }
+       exit(0);
+}
+
+$SIG{'INT'}  = \&signal;
+$SIG{'QUIT'} = \&signal;
+
 sub hest_update {
 
        my ($host_id, $share_id, $num) = @_;
@@ -197,6 +211,11 @@ sub hest_update {
                        $max--;
                }
 
+               if ($added % EST_SYNC_EVERY == 0) {
+                       print "sync ";
+                       $db->sync();
+               }
+
        }
 
        print "sync $added new files";