From d6f4757d2ed8ebf0eee31755d250c5ac701cba5e Mon Sep 17 00:00:00 2001 From: Dwight Date: Thu, 6 Mar 2008 18:06:06 -0500 Subject: [PATCH] safer --- db/query.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/db/query.cpp b/db/query.cpp index f5a4a68f393..3703ee4fb65 100644 --- a/db/query.cpp +++ b/db/query.cpp @@ -440,27 +440,31 @@ inline bool runCommands(const char *ns, JSObj& jsobj, stringstream& ss, BufBuild // delete a specific index if( f.type() == String ) { const char *idxName = f.valuestr(); - int x = d->findIndexByName(idxName); - if( x >= 0 ) { + if( *idxName == '*' && idxName[1] == 0 ) { + ok = true; cout << " d->nIndexes was " << d->nIndexes << endl; anObjBuilderForYa.append("nIndexesWas", (double)d->nIndexes); - d->nIndexes--; - for( int i = x; i < d->nIndexes; i++ ) - d->indexes[i] = d->indexes[i+1]; - ok=true; + anObjBuilderForYa.append("msg", "all indexes deleted for collection"); cout << " alpha implementation, space not reclaimed" << endl; - } else { - cout << "deleteIndexes: " << idxName << " not found" << endl; + d->nIndexes = 0; + } + else { + // delete just one index + int x = d->findIndexByName(idxName); + if( x >= 0 ) { + cout << " d->nIndexes was " << d->nIndexes << endl; + anObjBuilderForYa.append("nIndexesWas", (double)d->nIndexes); + d->nIndexes--; + for( int i = x; i < d->nIndexes; i++ ) + d->indexes[i] = d->indexes[i+1]; + ok=true; + cout << " alpha implementation, space not reclaimed" << endl; + } else { + cout << "deleteIndexes: " << idxName << " not found" << endl; + } } } } - else { - ok = true; - cout << " d->nIndexes was " << d->nIndexes << endl; - anObjBuilderForYa.append("nIndexesWas", (double)d->nIndexes); - cout << " alpha implementation, space not reclaimed" << endl; - d->nIndexes = 0; - } } else { anObjBuilderForYa.append("errmsg", "ns not found");