mirror of
https://github.com/gigablast/open-source-search-engine.git
synced 2024-10-04 20:27:43 +03:00
trying to get reset collection working
This commit is contained in:
parent
fff8b80969
commit
4321f02e4e
@ -630,25 +630,26 @@ bool Collectiondb::resetColl ( char *coll , bool resetTurkdb ) {
|
||||
return false;
|
||||
}
|
||||
// now must be "test" only for now
|
||||
if ( strcmp(coll,"test") ) { char *xx=NULL;*xx=0; }
|
||||
//if ( strcmp(coll,"test") ) { char *xx=NULL;*xx=0; }
|
||||
// no spiders can be out. they may be referencing the CollectionRec
|
||||
// in XmlDoc.cpp... quite likely.
|
||||
if ( g_conf.m_spideringEnabled ||
|
||||
g_spiderLoop.m_numSpidersOut > 0 ) {
|
||||
log("admin: Can not delete collection while "
|
||||
"spiders are enabled or active.");
|
||||
return false;
|
||||
}
|
||||
//if ( g_conf.m_spideringEnabled ||
|
||||
// g_spiderLoop.m_numSpidersOut > 0 ) {
|
||||
// log("admin: Can not delete collection while "
|
||||
// "spiders are enabled or active.");
|
||||
// return false;
|
||||
//}
|
||||
// do not allow this if in repair mode
|
||||
if ( g_repairMode > 0 ) {
|
||||
log("admin: Can not delete collection while in repair mode.");
|
||||
return false;
|
||||
}
|
||||
// get the CollectionRec for "test"
|
||||
CollectionRec *cr = getRec ( "test" );
|
||||
CollectionRec *cr = getRec ( coll ); // "test" );
|
||||
|
||||
// must be there. if not, we create test i guess
|
||||
if ( ! cr ) {
|
||||
log("db: could not get test coll rec");
|
||||
log("db: could not get coll rec \"%s\" to reset", coll);
|
||||
char *xx=NULL;*xx=0;
|
||||
}
|
||||
|
||||
@ -662,12 +663,17 @@ bool Collectiondb::resetColl ( char *coll , bool resetTurkdb ) {
|
||||
// do not copy the hashtable crap since you will have to re-init it!
|
||||
memcpy ( &tmp , cr , size ); // sizeof(CollectionRec) );
|
||||
|
||||
// tell cr's SafeBufs not to free their buffers since we did the
|
||||
// memcpy and their ptrs are now handled by "tmp" and will be passed
|
||||
// on to the new rec.
|
||||
g_parms.detachSafeBufs( cr );
|
||||
|
||||
// delete the test coll now
|
||||
if ( ! deleteRec ( "test" , resetTurkdb ) )
|
||||
if ( ! deleteRec ( coll , resetTurkdb ) )
|
||||
return log("admin: reset coll failed");
|
||||
|
||||
// make a collection called "test2" so that we copy "test"'s parms
|
||||
bool status = addRec ( "test" ,
|
||||
bool status = addRec ( coll ,
|
||||
NULL ,
|
||||
0 ,
|
||||
true , // bool isNew ,
|
||||
@ -679,7 +685,7 @@ bool Collectiondb::resetColl ( char *coll , bool resetTurkdb ) {
|
||||
// bail on error
|
||||
if ( ! status ) return log("admin: failed to add new coll for reset");
|
||||
// get its rec
|
||||
CollectionRec *nr = getRec ( "test" );
|
||||
CollectionRec *nr = getRec ( coll );
|
||||
// must be there
|
||||
if ( ! nr ) { char *xx=NULL;*xx=0; }
|
||||
// save this though, this might have changed!
|
||||
@ -693,6 +699,11 @@ bool Collectiondb::resetColl ( char *coll , bool resetTurkdb ) {
|
||||
// save it again after copy
|
||||
nr->save();
|
||||
|
||||
// tell cr's SafeBufs not to free their buffers since we did the
|
||||
// memcpy and their ptrs are now handled by "tmp" and will be passed
|
||||
// on to the new rec.
|
||||
g_parms.detachSafeBufs( &tmp );
|
||||
|
||||
// and clear the robots.txt cache in case we recently spidered a
|
||||
// robots.txt, we don't want to use it, we want to use the one we
|
||||
// have in the test-parser subdir so we are consistent
|
||||
|
46
Diffbot.cpp
46
Diffbot.cpp
@ -1620,6 +1620,11 @@ bool printCrawlBotPage ( TcpSocket *s ,
|
||||
if ( delColl )
|
||||
g_collectiondb.deleteRec ( delColl , true );
|
||||
|
||||
char *resetColl = hr->getString("resetcoll",NULL,NULL);
|
||||
if ( resetColl )
|
||||
g_collectiondb.resetColl ( resetColl );
|
||||
|
||||
|
||||
// set this to current collection. if only token was provided
|
||||
// then it will return the first collection owned by token.
|
||||
// if token has no collections it will be NULL.
|
||||
@ -2175,24 +2180,51 @@ bool printCrawlBotPage ( TcpSocket *s ,
|
||||
|
||||
|
||||
sb.safePrintf("<br>"
|
||||
|
||||
"<table cellpadding=5>"
|
||||
"<tr>"
|
||||
|
||||
"<td>"
|
||||
|
||||
|
||||
// reset collection form
|
||||
"<form method=get action=/crawlbot>"
|
||||
"<input type=hidden name=token value=\""
|
||||
);
|
||||
sb.safeMemcpy ( token , tokenLen );
|
||||
sb.safePrintf("\">"
|
||||
|
||||
"<input type=hidden name=delcoll value=%s>"
|
||||
"<table cellpadding=5>"
|
||||
"<tr>"
|
||||
|
||||
"<td>"
|
||||
"<input type=submit name=reset value=\""
|
||||
"<input type=hidden name=resetcoll value=%s>"
|
||||
// also show it in the display, so set "c"
|
||||
"<input type=hidden name=c value=%s>"
|
||||
"<input type=submit name=button value=\""
|
||||
"Reset this collection\">"
|
||||
"</form>"
|
||||
// end reset collection form
|
||||
|
||||
|
||||
"</td>"
|
||||
|
||||
"<td>"
|
||||
"<input type=submit name=delete value=\""
|
||||
|
||||
// delete collection form
|
||||
"<form method=get action=/crawlbot>"
|
||||
"<input type=hidden name=token value=\""
|
||||
, cr->m_coll
|
||||
, cr->m_coll
|
||||
);
|
||||
sb.safeMemcpy ( token , tokenLen );
|
||||
sb.safePrintf("\">"
|
||||
|
||||
"<input type=hidden name=delcoll value=%s>"
|
||||
"<input type=submit name=button value=\""
|
||||
"Delete this collection\">"
|
||||
"</form>"
|
||||
// end delete collection form
|
||||
|
||||
|
||||
|
||||
|
||||
"</td>"
|
||||
|
||||
"</tr>"
|
||||
|
12
Parms.cpp
12
Parms.cpp
@ -181,6 +181,18 @@ Parms::Parms ( ) {
|
||||
m_isDefaultLoaded = false;
|
||||
}
|
||||
|
||||
void Parms::detachSafeBufs ( CollectionRec *cr ) {
|
||||
for ( long i = 0 ; i < m_numParms ; i++ ) {
|
||||
Parm *m = &m_parms[i];
|
||||
if ( m->m_type != TYPE_SAFEBUF ) continue;
|
||||
if ( m->m_obj != OBJ_COLL ) continue;
|
||||
if ( m->m_off < 0 ) continue;
|
||||
// get it
|
||||
SafeBuf *sb = (SafeBuf *)((char *)cr + m->m_off);
|
||||
sb->detachBuf();
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long Parms::calcChecksum() {
|
||||
Checksum cs;
|
||||
|
||||
|
5
Parms.h
5
Parms.h
@ -247,6 +247,11 @@ class Parms {
|
||||
|
||||
char *getParmHtmlEncoded ( char *p , char *pend , Parm *m , char *s );
|
||||
|
||||
// . make it so a collectionrec can be copied in Collectiondb.cpp
|
||||
// . so the rec can be copied and the old one deleted without
|
||||
// freeing the safebufs now used by the new one.
|
||||
void detachSafeBufs ( class CollectionRec *cr ) ;
|
||||
|
||||
// calc checksum of parms
|
||||
unsigned long calcChecksum();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user