13 |
use POSIX qw/strftime/; |
use POSIX qw/strftime/; |
14 |
|
|
15 |
use constant BPC_FTYPE_DIR => 5; |
use constant BPC_FTYPE_DIR => 5; |
16 |
|
use constant EST_SYNC_EVERY => 10000; |
17 |
|
|
18 |
my $debug = 0; |
my $debug = 0; |
19 |
$|=1; |
$|=1; |
86 |
|
|
87 |
my $hest_db; |
my $hest_db; |
88 |
|
|
89 |
|
sub signal { |
90 |
|
my($sig) = @_; |
91 |
|
if ($hest_db) { |
92 |
|
print "\nCaught a SIG$sig--syncing database and shutting down\n"; |
93 |
|
$hest_db->sync(); |
94 |
|
$hest_db->close(); |
95 |
|
} |
96 |
|
exit(0); |
97 |
|
} |
98 |
|
|
99 |
|
$SIG{'INT'} = \&signal; |
100 |
|
$SIG{'QUIT'} = \&signal; |
101 |
|
|
102 |
sub hest_update { |
sub hest_update { |
103 |
|
|
104 |
my ($host_id, $share_id, $num) = @_; |
my ($host_id, $share_id, $num) = @_; |
105 |
|
|
106 |
print curr_time," updating HyperEstraier: files"; |
print curr_time," updating HyperEstraier: select files"; |
107 |
|
|
108 |
my $t = time(); |
my $t = time(); |
109 |
|
|
127 |
-- files.name AS filename, |
-- files.name AS filename, |
128 |
files.path AS filepath, |
files.path AS filepath, |
129 |
files.date AS date, |
files.date AS date, |
130 |
files.type AS filetype, |
files.type AS type, |
131 |
files.size AS size, |
files.size AS size, |
132 |
files.shareid AS shareid, |
files.shareid AS shareid, |
133 |
backups.date AS backup_date |
backups.date AS backup_date |
142 |
my $results = $sth->rows; |
my $results = $sth->rows; |
143 |
|
|
144 |
if ($results == 0) { |
if ($results == 0) { |
145 |
print " no files\n"; |
print " - no files, skipping\n"; |
146 |
return; |
return; |
147 |
} |
} |
148 |
|
|
159 |
|
|
160 |
my $max = int($results / $dot); |
my $max = int($results / $dot); |
161 |
|
|
162 |
print " index $index_path..."; |
print ", opening index $index_path..."; |
163 |
use HyperEstraier; |
use HyperEstraier; |
164 |
my $db = HyperEstraier::Database->new(); |
my $db = HyperEstraier::Database->new(); |
165 |
|
|
179 |
my $fid = $row->{'fid'} || die "no fid?"; |
my $fid = $row->{'fid'} || die "no fid?"; |
180 |
my $uri = 'file:///' . $fid; |
my $uri = 'file:///' . $fid; |
181 |
|
|
182 |
next if ($db->uri_to_id($uri)); |
my $id = $db->uri_to_id($uri); |
183 |
|
next unless ($id == -1); |
184 |
|
|
185 |
# create a document object |
# create a document object |
186 |
my $doc = HyperEstraier::Document->new; |
my $doc = HyperEstraier::Document->new; |
211 |
$max--; |
$max--; |
212 |
} |
} |
213 |
|
|
214 |
|
if ($added % EST_SYNC_EVERY == 0) { |
215 |
|
print "sync "; |
216 |
|
$db->sync(); |
217 |
|
} |
218 |
|
|
219 |
} |
} |
220 |
|
|
221 |
print "sync $added new files"; |
print "sync $added new files"; |
222 |
$db->sync(); |
$db->sync(); |
223 |
print " close"; |
print ", close"; |
224 |
$db->close(); |
$db->close(); |
225 |
|
|
226 |
my $dur = (time() - $t) || 1; |
my $dur = (time() - $t) || 1; |
235 |
|
|
236 |
|
|
237 |
## update index ## |
## update index ## |
238 |
if ($opt{i} || ($index_path && ! -e $index_path)) { |
if (($opt{i} || ($index_path && ! -e $index_path)) && !$opt{c}) { |
239 |
# update all |
# update all |
240 |
print "force update of HyperEstraier index "; |
print "force update of HyperEstraier index "; |
241 |
print "importing existing data" unless (-e $index_path); |
print "importing existing data" unless (-e $index_path); |