Skip to content

Commit

Permalink
remove boost filesystem includes from pch.h and be explicit anywhere …
Browse files Browse the repository at this point in the history
…we use it
  • Loading branch information
erh committed Jan 5, 2012
1 parent 717c7a2 commit 432a839
Show file tree
Hide file tree
Showing 40 changed files with 166 additions and 112 deletions.
2 changes: 2 additions & 0 deletions src/mongo/client/distlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "dbclient.h"
#include "distlock.h"

#include <boost/thread/once.hpp>

namespace mongo {

LabeledLevel DistributedLock::logLvl( 1 );
Expand Down
2 changes: 2 additions & 0 deletions src/mongo/client/examples/mongoperf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "../../util/time_support.h"
#include "../../bson/util/atomic_int.h"

#include <boost/filesystem/operations.hpp>

using namespace std;
using namespace mongo;
using namespace bson;
Expand Down
2 changes: 2 additions & 0 deletions src/mongo/client/gridfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#define MIN(a,b) ( (a) < (b) ? (a) : (b) )
#endif

#include <boost/filesystem/operations.hpp>

namespace mongo {

const unsigned DEFAULT_CHUNK_SIZE = 256 * 1024;
Expand Down
2 changes: 2 additions & 0 deletions src/mongo/db/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#define MAX_LINE_LENGTH 256

#include <boost/filesystem/operations.hpp>

namespace po = boost::program_options;
namespace fs = boost::filesystem;

Expand Down
2 changes: 2 additions & 0 deletions src/mongo/db/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "clientcursor.h"
#include "databaseholder.h"

#include <boost/filesystem/operations.hpp>

namespace mongo {

bool Database::_openAllFiles = true;
Expand Down
4 changes: 3 additions & 1 deletion src/mongo/db/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
# include <sys/file.h>
#endif

#include <boost/filesystem/operations.hpp>

namespace mongo {

namespace dur {
Expand Down Expand Up @@ -466,7 +468,7 @@ namespace mongo {
}

acquirePathLock(forceRepair);
remove_all( dbpath + "/_tmp/" );
boost::filesystem::remove_all( dbpath + "/_tmp/" );

FileAllocator::get()->start();

Expand Down
5 changes: 4 additions & 1 deletion src/mongo/db/dbcommands_admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include "../scripting/engine.h"
#include "../util/timer.h"

#include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/operations.hpp>

namespace mongo {

class CleanCmd : public Command {
Expand Down Expand Up @@ -89,7 +92,7 @@ namespace mongo {

// remove file if already present
try {
remove(p);
boost::filesystem::remove(p);
}
catch(...) { }

Expand Down
5 changes: 4 additions & 1 deletion src/mongo/db/dbhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "ops/update.h"
#include "ops/delete.h"

#include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/operations.hpp>

namespace mongo {

void Helpers::ensureIndex(const char *ns, BSONObj keyPattern, bool unique, const char *name) {
Expand Down Expand Up @@ -335,7 +338,7 @@ namespace mongo {

void RemoveSaver::goingToDelete( const BSONObj& o ) {
if ( ! _out ) {
create_directories( _root );
boost::filesystem::create_directories( _root );
_out = new ofstream();
_out->open( _file.string().c_str() , ios_base::out | ios_base::binary );
if ( ! _out->good() ) {
Expand Down
4 changes: 2 additions & 2 deletions src/mongo/db/dbhelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ namespace mongo {
void goingToDelete( const BSONObj& o );

private:
path _root;
path _file;
boost::filesystem::path _root;
boost::filesystem::path _file;
ofstream* _out;

};
Expand Down
26 changes: 14 additions & 12 deletions src/mongo/db/dur_journal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

using namespace mongoutils;

#include <boost/filesystem/operations.hpp>

namespace mongo {

class AlignedBuilder;
Expand Down Expand Up @@ -71,15 +73,15 @@ namespace mongo {

bool usingPreallocate = false;

void removeOldJournalFile(path p);
void removeOldJournalFile(boost::filesystem::path p);

boost::filesystem::path getJournalDir() {
boost::filesystem::path p(dbpath);
p /= "journal";
return p;
}

path lsnPath() {
boost::filesystem::path lsnPath() {
return getJournalDir()/"lsn";
}

Expand Down Expand Up @@ -157,7 +159,7 @@ namespace mongo {
_writeToLSNNeeded = false;
}

path Journal::getFilePathFor(int filenumber) const {
boost::filesystem::path Journal::getFilePathFor(int filenumber) const {
boost::filesystem::path p(dir);
p /= string(str::stream() << "j._" << filenumber);
return p;
Expand Down Expand Up @@ -371,7 +373,7 @@ namespace mongo {
j.open();
}

void removeOldJournalFile(path p) {
void removeOldJournalFile(boost::filesystem::path p) {
if( usingPreallocate ) {
try {
for( int i = 0; i < NUM_PREALLOC_FILES; i++ ) {
Expand Down Expand Up @@ -410,7 +412,7 @@ namespace mongo {
}

// find a prealloc.<n> file, presumably to take and use
path findPrealloced() {
boost::filesystem::path findPrealloced() {
try {
for( int i = 0; i < NUM_PREALLOC_FILES; i++ ) {
boost::filesystem::path filepath = preallocPath(i);
Expand All @@ -420,7 +422,7 @@ namespace mongo {
} catch(...) {
log() << "warning exception in dur::findPrealloced()" << endl;
}
return path();
return boost::filesystem::path();
}

/** assure journal/ dir exists. throws. call during startup. */
Expand All @@ -430,9 +432,9 @@ namespace mongo {
boost::filesystem::path p = getJournalDir();
j.dir = p.string();
log() << "journal dir=" << j.dir << endl;
if( !exists(j.dir) ) {
if( !boost::filesystem::exists(j.dir) ) {
try {
create_directory(j.dir);
boost::filesystem::create_directory(j.dir);
}
catch(std::exception& e) {
log() << "error creating directory " << j.dir << ' ' << e.what() << endl;
Expand All @@ -444,11 +446,11 @@ namespace mongo {
void Journal::_open() {
_curFileId = 0;
assert( _curLogFile == 0 );
path fname = getFilePathFor(_nextFileNumber);
boost::filesystem::path fname = getFilePathFor(_nextFileNumber);

// if we have a prealloced file, use it
{
path p = findPrealloced();
boost::filesystem::path p = findPrealloced();
if( !p.empty() ) {
try {
{
Expand Down Expand Up @@ -512,7 +514,7 @@ namespace mongo {
/** called during recovery (the error message text below assumes that)
*/
unsigned long long journalReadLSN() {
if( !MemoryMappedFile::exists(lsnPath()) ) {
if( !exists(lsnPath()) ) {
log() << "info no lsn file in journal/ directory" << endl;
return 0;
}
Expand Down Expand Up @@ -607,7 +609,7 @@ namespace mongo {

if( f.lastEventTimeMs < _lastFlushTime + ExtraKeepTimeMs ) {
// eligible for deletion
path p( f.filename );
boost::filesystem::path p( f.filename );
log() << "old journal file will be removed: " << f.filename << endl;
removeOldJournalFile(p);
}
Expand Down
20 changes: 11 additions & 9 deletions src/mongo/db/dur_recover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

using namespace mongoutils;

#include <boost/filesystem/operations.hpp>

namespace mongo {

namespace dur {
Expand All @@ -62,11 +64,11 @@ namespace mongo {
};

void removeJournalFiles();
path getJournalDir();
boost::filesystem::path getJournalDir();

/** get journal filenames, in order. throws if unexpected content found */
static void getFiles(path dir, vector<path>& files) {
map<unsigned,path> m;
static void getFiles(boost::filesystem::path dir, vector<boost::filesystem::path>& files) {
map<unsigned,boost::filesystem::path> m;
for ( boost::filesystem::directory_iterator i( dir );
i != boost::filesystem::directory_iterator();
++i ) {
Expand All @@ -77,10 +79,10 @@ namespace mongo {
if( m.count(u) ) {
uasserted(13531, str::stream() << "unexpected files in journal directory " << dir.string() << " : " << fileName);
}
m.insert( pair<unsigned,path>(u,filepath) );
m.insert( pair<unsigned,boost::filesystem::path>(u,filepath) );
}
}
for( map<unsigned,path>::iterator i = m.begin(); i != m.end(); ++i ) {
for( map<unsigned,boost::filesystem::path>::iterator i = m.begin(); i != m.end(); ++i ) {
if( i != m.begin() && m.count(i->first - 1) == 0 ) {
uasserted(13532,
str::stream() << "unexpected file in journal directory " << dir.string()
Expand Down Expand Up @@ -191,7 +193,7 @@ namespace mongo {
ss << fileNo;

// relative name -> full path name
path full(dbpath);
boost::filesystem::path full(dbpath);
full /= ss.str();
return full.string();
}
Expand Down Expand Up @@ -430,7 +432,7 @@ namespace mongo {
}

/** apply a specific journal file */
bool RecoveryJob::processFile(path journalfile) {
bool RecoveryJob::processFile(boost::filesystem::path journalfile) {
log() << "recover " << journalfile.string() << endl;

try {
Expand All @@ -450,7 +452,7 @@ namespace mongo {
}

/** @param files all the j._0 style files we need to apply for recovery */
void RecoveryJob::go(vector<path>& files) {
void RecoveryJob::go(vector<boost::filesystem::path>& files) {
log() << "recover begin" << endl;
_recovering = true;

Expand Down Expand Up @@ -490,7 +492,7 @@ namespace mongo {
return;
}

vector<path> journalFiles;
vector<boost::filesystem::path> journalFiles;
getFiles(p, journalFiles);

if( journalFiles.empty() ) {
Expand Down
4 changes: 2 additions & 2 deletions src/mongo/db/dur_recover.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace mongo {
public:
RecoveryJob() : _lastDataSyncedFromLastRun(0),
_mx("recovery"), _recovering(false) { _lastSeqMentionedInConsoleLog = 1; }
void go(vector<path>& files);
void go(vector<boost::filesystem::path>& files);
~RecoveryJob();

/** @param data data between header and footer. compressed if recovering. */
Expand All @@ -32,7 +32,7 @@ namespace mongo {
void applyEntry(const ParsedJournalEntry& entry, bool apply, bool dump);
void applyEntries(const vector<ParsedJournalEntry> &entries);
bool processFileBuffer(const void *, unsigned len);
bool processFile(path journalfile);
bool processFile(boost::filesystem::path journalfile);
void _close(); // doesn't lock

list<boost::shared_ptr<MongoMMF> > _mmfs;
Expand Down
12 changes: 7 additions & 5 deletions src/mongo/db/durop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

using namespace mongoutils;

#include <boost/filesystem/operations.hpp>

namespace mongo {

extern string dbpath; // --dbpath parm
Expand Down Expand Up @@ -109,28 +111,28 @@ namespace mongo {

// if an operation deletes or creates a file (or moves etc.), it may need files closed.
bool FileCreatedOp::needFilesClosed() {
return exists( _p.asFullPath() );
return boost::filesystem::exists( _p.asFullPath() );
}

void FileCreatedOp::replay() {
// i believe the code assumes new files are filled with zeros. thus we have to recreate the file,
// or rewrite at least, even if it were the right length. perhaps one day we should change that
// although easier to avoid defects if we assume it is zeros perhaps.
string full = _p.asFullPath();
if( exists(full) ) {
if( boost::filesystem::exists(full) ) {
try {
remove(full);
boost::filesystem::remove(full);
}
catch(std::exception& e) {
log(1) << "recover info FileCreateOp::replay unlink " << e.what() << endl;
}
}

log() << "recover create file " << full << ' ' << _len/1024.0/1024.0 << "MB" << endl;
if( MemoryMappedFile::exists(full) ) {
if( boost::filesystem::exists(full) ) {
// first delete if exists.
try {
remove(full);
boost::filesystem::remove(full);
}
catch(...) {
log() << "warning could not delete file " << full << endl;
Expand Down
5 changes: 4 additions & 1 deletion src/mongo/db/extsort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include <sys/stat.h>
#include <fcntl.h>

#include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/operations.hpp>

namespace mongo {

IndexInterface *BSONObjExternalSorter::extSortIdxInterface;
Expand Down Expand Up @@ -225,7 +228,7 @@ namespace mongo {
unsigned long long length;
_buf = (char*)_file.map( file.c_str() , length , MemoryMappedFile::SEQUENTIAL );
massert( 10308 , "mmap failed" , _buf );
assert( length == (unsigned long long) file_size( file ) );
assert( length == (unsigned long long)boost::filesystem::file_size( file ) );
_end = _buf + length;
}
BSONObjExternalSorter::FileIterator::~FileIterator() {}
Expand Down
2 changes: 1 addition & 1 deletion src/mongo/db/extsort.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace mongo {

BSONObj _order;
long _maxFilesize;
path _root;
boost::filesystem::path _root;

int _arraySize;
InMemory * _cur;
Expand Down
4 changes: 3 additions & 1 deletion src/mongo/db/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#include "ops/update.h"
#include "pagefault.h"

#include <boost/filesystem/operations.hpp>

namespace mongo {

// "diaglog"
Expand Down Expand Up @@ -749,7 +751,7 @@ namespace mongo {
boost::filesystem::path p = *i;
string dbName = p.leaf();
p /= ( dbName + ".ns" );
if ( MMF::exists( p ) )
if ( exists( p ) )
names.push_back( dbName );
}
else {
Expand Down
Loading

0 comments on commit 432a839

Please sign in to comment.