mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-24 00:29:35 -05:00
ITS#4554 slapindex takes a list of attributes to index
This commit is contained in:
parent
58b918bea2
commit
5d3f3c240d
4 changed files with 77 additions and 6 deletions
|
|
@ -579,7 +579,8 @@ done:
|
|||
|
||||
int bdb_tool_entry_reindex(
|
||||
BackendDB *be,
|
||||
ID id )
|
||||
ID id,
|
||||
AttributeDescription **adv )
|
||||
{
|
||||
struct bdb_info *bi = (struct bdb_info *) be->be_private;
|
||||
int rc;
|
||||
|
|
@ -599,6 +600,45 @@ int bdb_tool_entry_reindex(
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Check for explicit list of attrs to index */
|
||||
if ( adv ) {
|
||||
int i, j, n;
|
||||
|
||||
/* count */
|
||||
for ( n = 0; adv[n]; n++ ) ;
|
||||
|
||||
/* insertion sort */
|
||||
for ( i = 0; i < n; i++ ) {
|
||||
AttributeDescription *ad = adv[i];
|
||||
for ( j = i-1; j>=0; j--) {
|
||||
if ( SLAP_PTRCMP( adv[j], ad ) <= 0 ) break;
|
||||
adv[j+1] = adv[j];
|
||||
}
|
||||
adv[j+1] = ad;
|
||||
}
|
||||
|
||||
for ( i = 0; adv[i]; i++ ) {
|
||||
if ( bi->bi_attrs[i]->ai_desc != adv[i] ) {
|
||||
for ( j = i+1; j < bi->bi_nattrs; j++ ) {
|
||||
if ( bi->bi_attrs[j]->ai_desc == adv[i] ) {
|
||||
AttrInfo *ai = bi->bi_attrs[i];
|
||||
bi->bi_attrs[i] = bi->bi_attrs[j];
|
||||
bi->bi_attrs[j] = ai;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( j == bi->bi_nattrs ) {
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
LDAP_XSTRING(bdb_tool_entry_reindex)
|
||||
": no index configured for %s\n",
|
||||
adv[i]->ad_cname.bv_val, 0, 0 );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
bi->bi_nattrs = i;
|
||||
}
|
||||
|
||||
/* Get the first attribute to index */
|
||||
if (bi->bi_linear_index && !index_nattrs) {
|
||||
index_nattrs = bi->bi_nattrs - 1;
|
||||
|
|
|
|||
|
|
@ -2077,7 +2077,7 @@ typedef ID (BI_tool_entry_next) LDAP_P(( BackendDB *be ));
|
|||
typedef Entry* (BI_tool_entry_get) LDAP_P(( BackendDB *be, ID id ));
|
||||
typedef ID (BI_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e,
|
||||
struct berval *text ));
|
||||
typedef int (BI_tool_entry_reindex) LDAP_P(( BackendDB *be, ID id ));
|
||||
typedef int (BI_tool_entry_reindex) LDAP_P(( BackendDB *be, ID id, AttributeDescription **adv ));
|
||||
typedef int (BI_tool_sync) LDAP_P(( BackendDB *be ));
|
||||
typedef ID (BI_tool_dn2id_get) LDAP_P(( BackendDB *be, struct berval *dn ));
|
||||
typedef int (BI_tool_id2entry_get) LDAP_P(( BackendDB *be, ID id, Entry **e ));
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ usage( int tool, const char *progname )
|
|||
break;
|
||||
|
||||
case SLAPINDEX:
|
||||
options = " [-c]\n\t[-g] [-n databasenumber | -b suffix] [-q]\n";
|
||||
options = " [-c]\n\t[-g] [-n databasenumber | -b suffix] [attr ...] [-q]\n";
|
||||
break;
|
||||
|
||||
case SLAPTEST:
|
||||
|
|
@ -441,13 +441,19 @@ slap_tool_init(
|
|||
switch ( tool ) {
|
||||
case SLAPADD:
|
||||
case SLAPCAT:
|
||||
case SLAPINDEX:
|
||||
if ( ( argc != optind ) || (dbnum >= 0 && base.bv_val != NULL ) ) {
|
||||
usage( tool, progname );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SLAPINDEX:
|
||||
if ( dbnum >= 0 && base.bv_val != NULL ) {
|
||||
usage( tool, progname );
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SLAPDN:
|
||||
if ( argc == optind ) {
|
||||
usage( tool, progname );
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ slapindex( int argc, char **argv )
|
|||
ID id;
|
||||
int rc = EXIT_SUCCESS;
|
||||
const char *progname = "slapindex";
|
||||
AttributeDescription *ad, **adv = NULL;
|
||||
|
||||
slap_tool_init( progname, SLAPINDEX, argc, argv );
|
||||
|
||||
|
|
@ -51,12 +52,32 @@ slapindex( int argc, char **argv )
|
|||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
if ( argc > 0 ) {
|
||||
const char *text;
|
||||
int i;
|
||||
|
||||
argv = &argv[optind];
|
||||
adv = (AttributeDescription **)argv;
|
||||
|
||||
for (i = 0; i < argc; i++ ) {
|
||||
ad = NULL;
|
||||
rc = slap_str2ad( argv[i], &ad, &text );
|
||||
if ( rc != LDAP_SUCCESS ) {
|
||||
fprintf( stderr, "slap_str2ad(%s) failed %d (%s)\n",
|
||||
argv[i], rc, ldap_err2string( rc ));
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
adv[i] = ad;
|
||||
}
|
||||
}
|
||||
|
||||
if( be->be_entry_open( be, 0 ) != 0 ) {
|
||||
fprintf( stderr, "%s: could not open database.\n",
|
||||
progname );
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
|
||||
for ( id = be->be_entry_first( be );
|
||||
id != NOID;
|
||||
id = be->be_entry_next( be ) )
|
||||
|
|
@ -67,7 +88,11 @@ slapindex( int argc, char **argv )
|
|||
printf("indexing id=%08lx\n", (long) id );
|
||||
}
|
||||
|
||||
rtn = be->be_entry_reindex( be, id );
|
||||
/* Backend will set its attr list on first call. Clear
|
||||
* the list on all subsequent calls.
|
||||
*/
|
||||
rtn = be->be_entry_reindex( be, id, adv );
|
||||
adv = NULL;
|
||||
|
||||
if( rtn != LDAP_SUCCESS ) {
|
||||
rc = EXIT_FAILURE;
|
||||
|
|
|
|||
Loading…
Reference in a new issue