From c775624c9faa69331cff3dcc5d242de36346e51f Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 28 Jan 2002 20:36:29 +0000 Subject: [PATCH] Check the ldif file without actually creating the db (but inits the files; maybe I should trim this also). Useful to check LARGE ldif files which will require TONS on indices without failing at the very last entry for a silly typo after 45 min. or more :) --- servers/slapd/tools/slapadd.c | 32 ++++++++++++++++++-------------- servers/slapd/tools/slapcommon.c | 7 ++++++- servers/slapd/tools/slapcommon.h | 1 + 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/servers/slapd/tools/slapadd.c b/servers/slapd/tools/slapadd.c index 55e0d4fe08..b6b05bdae7 100644 --- a/servers/slapd/tools/slapadd.c +++ b/servers/slapd/tools/slapadd.c @@ -52,7 +52,6 @@ main( int argc, char **argv ) } while( ldif_read_record( ldiffp, &lineno, &buf, &lmax ) ) { - ID id; Entry *e = str2entry( buf ); struct berval bvtext = { textlen, textbuf }; @@ -146,20 +145,25 @@ main( int argc, char **argv ) } } - id = be->be_entry_put( be, e, &bvtext ); - if( id == NOID ) { - fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d): %s\n", - progname, e->e_dn, lineno, bvtext.bv_val ); - rc = EXIT_FAILURE; - entry_free( e ); - if( continuemode ) continue; - break; - - } + if (!dryrun) { + ID id = be->be_entry_put( be, e, &bvtext ); + if( id == NOID ) { + fprintf( stderr, "%s: could not add entry dn=\"%s\" (line=%d): %s\n", + progname, e->e_dn, lineno, bvtext.bv_val ); + rc = EXIT_FAILURE; + entry_free( e ); + if( continuemode ) continue; + break; + } - if ( verbose ) { - fprintf( stderr, "added: \"%s\" (%08lx)\n", - e->e_dn, (long) id ); + if ( verbose ) { + fprintf( stderr, "added: \"%s\" (%08lx)\n", + e->e_dn, (long) id ); + } + } else { + if ( verbose ) { + fprintf( stderr, "(dry) added: \"%s\"\n", e->e_dn ); + } } entry_free( e ); diff --git a/servers/slapd/tools/slapcommon.c b/servers/slapd/tools/slapcommon.c index 8343877c8e..bcea08993f 100644 --- a/servers/slapd/tools/slapcommon.c +++ b/servers/slapd/tools/slapcommon.c @@ -25,6 +25,7 @@ int truncatemode = 0; int verbose = 0; int continuemode = 0; int nosubordinates = 0; +int dryrun = 0; char *ldiffile = NULL; FILE *ldiffp = NULL; @@ -97,7 +98,7 @@ slap_tool_init( switch( tool ) { case SLAPADD: - options = "b:cd:f:l:n:tv"; + options = "b:cd:f:l:n:tuv"; break; case SLAPINDEX: @@ -148,6 +149,10 @@ slap_tool_init( mode |= SLAP_TRUNCATE_MODE; break; + case 'u': /* dry run */ + dryrun++; + break; + case 'v': /* turn on verbose */ verbose++; break; diff --git a/servers/slapd/tools/slapcommon.h b/servers/slapd/tools/slapcommon.h index 2dd0c48544..aef22fcc62 100644 --- a/servers/slapd/tools/slapcommon.h +++ b/servers/slapd/tools/slapcommon.h @@ -26,6 +26,7 @@ extern int appendmode; extern int verbose; extern int continuemode; extern int nosubordinates; +extern int dryrun; extern char *ldiffile; extern FILE *ldiffp; -- 2.39.5