X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fslapadd.c;h=d975034313f1696bcc9b29f647347dcab4f2fc96;hb=6d1aa51604a7ae9c44287af5201afc9f43b5e91e;hp=9369d7c6908dde521cb934cf9494ae6b8af47ee6;hpb=ccaf69a7bccba0524498306b1295c2d5a07da69e;p=openldap diff --git a/servers/slapd/slapadd.c b/servers/slapd/slapadd.c index 9369d7c690..d975034313 100644 --- a/servers/slapd/slapadd.c +++ b/servers/slapd/slapadd.c @@ -1,7 +1,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2008 The OpenLDAP Foundation. + * Copyright 1998-2009 The OpenLDAP Foundation. * Portions Copyright 1998-2003 Kurt D. Zeilenga. * Portions Copyright 2003 IBM Corporation. * All rights reserved. @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include "slapcommon.h" @@ -67,9 +69,14 @@ slapadd( int argc, char **argv ) int rc = EXIT_SUCCESS; int manage = 0; + int enable_meter = 0; + lutil_meter_t meter; + struct stat stat_buf; + /* default "000" */ csnsid = 0; + if ( isatty (2) ) enable_meter = 1; slap_tool_init( progname, SLAPADD, argc, argv ); memset( &opbuf, 0, sizeof(opbuf) ); @@ -118,6 +125,22 @@ slapadd( int argc, char **argv ) } } + if ( enable_meter +#ifdef LDAP_DEBUG + /* tools default to "none" */ + && slap_debug == LDAP_DEBUG_NONE +#endif + && !fstat ( fileno ( ldiffp->fp ), &stat_buf ) + && S_ISREG(stat_buf.st_mode) ) { + enable_meter = !lutil_meter_open( + &meter, + &lutil_meter_text_display, + &lutil_meter_linear_estimator, + stat_buf.st_size); + } else { + enable_meter = 0; + } + /* nextline is the line number of the end of the current entry */ for( lineno=1; ldif_read_record( ldiffp, &nextline, &buf, &lmax ); lineno=nextline+1 ) { @@ -128,6 +151,11 @@ slapadd( int argc, char **argv ) e = str2entry2( buf, checkvals ); + if ( enable_meter ) + lutil_meter_update( &meter, + ftell( ldiffp->fp ), + 0); + /* * Initialize text buffer */ @@ -192,7 +220,7 @@ slapadd( int argc, char **argv ) op->o_bd = be; if ( (slapMode & SLAP_TOOL_NO_SCHEMA_CHECK) == 0) { - rc = entry_schema_check( op, e, NULL, manage, 1, + rc = entry_schema_check( op, e, NULL, manage, 1, NULL, &text, textbuf, textlen ); if( rc != LDAP_SUCCESS ) { @@ -203,6 +231,7 @@ slapadd( int argc, char **argv ) if( continuemode ) continue; break; } + textbuf[ 0 ] = '\0'; } } @@ -344,6 +373,11 @@ slapadd( int argc, char **argv ) bvtext.bv_val = textbuf; bvtext.bv_val[0] = '\0'; + if ( enable_meter ) { + lutil_meter_update( &meter, ftell( ldiffp->fp ), 1); + lutil_meter_close( &meter ); + } + if ( rc == EXIT_SUCCESS && update_ctxcsn && !dryrun && sid != SLAP_SYNC_SID_MAX + 1 ) { ctxcsn_id = be->be_dn2id_get( be, be->be_nsuffix ); if ( ctxcsn_id == NOID ) { @@ -437,6 +471,9 @@ slapadd( int argc, char **argv ) ch_free( buf ); if ( !dryrun ) { + if ( enable_meter ) { + fprintf( stderr, "Closing DB..." ); + } if( be->be_entry_close( be ) ) { rc = EXIT_FAILURE; } @@ -444,9 +481,13 @@ slapadd( int argc, char **argv ) if( be->be_sync ) { be->be_sync( be ); } + if ( enable_meter ) { + fprintf( stderr, "\n" ); + } } - slap_tool_destroy(); + if ( slap_tool_destroy()) + rc = EXIT_FAILURE; return rc; }