0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 17:10:48 +01:00

minor: whitespace

This commit is contained in:
Mike Dirolf 2009-08-06 14:12:32 -04:00
parent bc480966e5
commit 32f5ebb4c6
3 changed files with 45 additions and 45 deletions

View File

@ -12,7 +12,7 @@ using namespace std;
using namespace mongo;
int main( int argc, const char **argv ) {
const char *port = "27017";
if ( argc != 1 ) {
if ( argc != 3 )
@ -133,39 +133,39 @@ int main( int argc, const char **argv ) {
// run validate
assert( conn.validate( ns ) );
}
{ // timestamp test
const char * tsns = "test.tstest1";
conn.dropCollection( tsns );
{
mongo::BSONObjBuilder b;
b.appendTimestamp( "ts" );
conn.insert( tsns , b.obj() );
}
mongo::BSONObj out = conn.findOne( tsns , mongo::BSONObj() );
unsigned long long oldTime = out["ts"].timestampTime();
unsigned int oldInc = out["ts"].timestampInc();
{
mongo::BSONObjBuilder b1;
b1.append( out["_id"] );
mongo::BSONObjBuilder b2;
b2.append( out["_id"] );
b2.appendTimestamp( "ts" );
conn.update( tsns , b1.obj() , b2.obj() );
}
BSONObj found = conn.findOne( tsns , mongo::BSONObj() );
assert( ( oldTime < found["ts"].timestampTime() ) ||
( oldInc + 1 == found["ts"].timestampInc() ) );
}
{
list<string> l = conn.getDatabaseNames();
for ( list<string>::iterator i = l.begin(); i != l.end(); i++ ){

View File

@ -40,19 +40,19 @@ namespace mongo {
}
GridFS::~GridFS(){
}
BSONObj GridFS::storeFile( const string& fileName ){
uassert( "file doesn't exist" , boost::filesystem::exists( fileName ) );
gridfs_offset length = boost::filesystem::file_size( fileName );
BSONObjBuilder fileObject;
BSONObj idObj;
OID id;
{
id.init();
fileObject.appendOID( "_id" , &id );
@ -65,28 +65,28 @@ namespace mongo {
b.appendOID( "_id" , &id );
idObj = b.obj();
}
char buf[DEFAULT_CHUNK_SIZE];
gridfs_offset pos = 0;
FILE* fd = fopen( fileName.c_str() , "rb" );
int chunkNumber = 0;
while ( pos < length ){
int l = fread( buf , 1, MIN( DEFAULT_CHUNK_SIZE , length - pos ), fd );
Chunk c( idObj , chunkNumber , buf , l );
_client.insert( _chunksNS.c_str() , c._data );
pos += l;
chunkNumber++;
}
fclose( fd );
BSONObj res;
if ( ! _client.runCommand( _dbName.c_str() , BSON( "filemd5" << id << "root" << _prefix ) , res ) )
throw UserException( "filemd5 failed" );
fileObject.appendAs( res["md5"] , "md5" );
BSONObj real = fileObject.obj();
@ -98,18 +98,18 @@ namespace mongo {
void GridFS::removeFile( const string& fileName ){
BSONObj idObj = _client.findOne( _filesNS , BSON( "filename" << fileName ) );
if ( !idObj.isEmpty() ){
_client.remove( _filesNS.c_str() , BSON( "filename" << fileName ) );
_client.remove( _chunksNS.c_str() , BSON( "files_id" << idObj["_id"] ) );
}
_client.remove( _filesNS.c_str() , BSON( "filename" << fileName ) );
_client.remove( _chunksNS.c_str() , BSON( "files_id" << idObj["_id"] ) );
}
}
GridFile::GridFile( GridFS * grid , BSONObj obj ){
_grid = grid;
_obj = obj;
}
GridFile GridFS::findFile( const string& fileName ){
return findFile( BSON( "filename" << fileName ) );
GridFile GridFS::findFile( const string& fileName ){
return findFile( BSON( "filename" << fileName ) );
};
GridFile GridFS::findFile( BSONObj query ){
@ -137,9 +137,9 @@ namespace mongo {
gridfs_offset GridFile::write( ostream & out ){
_exists();
const int num = getNumChunks();
for ( int i=0; i<num; i++ ){
Chunk c = getChunk( i );
@ -150,7 +150,7 @@ namespace mongo {
return getContentLength();
}
gridfs_offset GridFile::write( const string& where ){
ofstream out(where.c_str() , ios::out | ios::binary );
return write( out );
@ -159,5 +159,5 @@ namespace mongo {
void GridFile::_exists(){
uassert( "doesn't exists" , exists() );
}
}

View File

@ -15,7 +15,7 @@ namespace mongo {
public:
Chunk( BSONObj data );
Chunk( BSONObj fileId , int chunkNumber , const char * data , int len );
int len(){
int len;
const char * data = _data["data"].binData( len );
@ -23,16 +23,16 @@ namespace mongo {
assert( len - 4 == foo[0] );
return len - 4;
}
const char * data( int & len ){
const char * data = _data["data"].binData( len );
int * foo = (int*)data;
assert( len - 4 == foo[0] );
len = len - 4;
return data + 4;
}
private:
BSONObj _data;
friend class GridFS;
@ -58,14 +58,14 @@ namespace mongo {
* @return the file object
*/
BSONObj storeFile( const string& fileName );
/**
* removes file referenced by fileName from the db
* @param fileName relative to process
* @return the file object
*/
void removeFile( const string& fileName );
/**
* returns a file object matching the query
*/
@ -95,7 +95,7 @@ namespace mongo {
friend class GridFile;
};
/**
wrapper for a file stored in the Mongo database
*/
@ -108,11 +108,11 @@ namespace mongo {
bool exists(){
return ! _obj.isEmpty();
}
string getFilename(){
return _obj["filename"].str();
}
int getChunkSize(){
return (int)(_obj["chunkSize"].number());
}
@ -136,17 +136,17 @@ namespace mongo {
write the file to this filename
*/
gridfs_offset write( const string& where );
private:
GridFile( GridFS * grid , BSONObj obj );
void _exists();
GridFS * _grid;
BSONObj _obj;
friend class GridFS;
};
}