Ejemplo n.º 1
0
 void _deleteDataFiles(const char *database) {
     if (storageGlobalParams.directoryperdb) {
         FileAllocator::get()->waitUntilFinished();
         MONGO_ASSERT_ON_EXCEPTION_WITH_MSG(
                 boost::filesystem::remove_all(
                     boost::filesystem::path(storageGlobalParams.dbpath) / database),
                                             "delete data files with a directoryperdb");
         return;
     }
     class : public FileOp {
         virtual bool apply( const boost::filesystem::path &p ) {
             return boost::filesystem::remove( p );
         }
         virtual const char * op() const {
             return "remove";
         }
     } deleter;
     _applyOpToDataFiles( database, deleter, true );
 }
Ejemplo n.º 2
0
 // move temp files to standard data dir
 void _replaceWithRecovered( const string& database, const char *reservedPathString ) {
     Path newPath(storageGlobalParams.dbpath);
     if (storageGlobalParams.directoryperdb)
         newPath /= database;
     class Replacer : public FileOp {
     public:
         Replacer( const Path &newPath ) : newPath_( newPath ) {}
     private:
         const boost::filesystem::path &newPath_;
         virtual bool apply( const Path &p ) {
             if ( !boost::filesystem::exists( p ) )
                 return false;
             boostRenameWrapper( p, newPath_ / p.leaf() );
             return true;
         }
         virtual const char * op() const {
             return "renaming";
         }
     } replacer( newPath );
     _applyOpToDataFiles( database, replacer, true, reservedPathString );
 }
Ejemplo n.º 3
0
 // back up original database files to 'temp' dir
 void _renameForBackup( const std::string& database, const Path &reservedPath ) {
     Path newPath( reservedPath );
     if (storageGlobalParams.directoryperdb)
         newPath /= database;
     class Renamer : public FileOp {
     public:
         Renamer( const Path &newPath ) : newPath_( newPath ) {}
     private:
         const boost::filesystem::path &newPath_;
         virtual bool apply( const Path &p ) {
             if ( !boost::filesystem::exists( p ) )
                 return false;
             boostRenameWrapper( p, newPath_ / ( p.leaf().string() + ".bak" ) );
             return true;
         }
         virtual const char * op() const {
             return "renaming";
         }
     } renamer( newPath );
     _applyOpToDataFiles( database, renamer, true );
 }
Ejemplo n.º 4
0
 intmax_t dbSize( const string& database ) {
     class SizeAccumulator : public FileOp {
     public:
         SizeAccumulator() : totalSize_( 0 ) {}
         intmax_t size() const {
             return totalSize_;
         }
     private:
         virtual bool apply( const boost::filesystem::path &p ) {
             if ( !boost::filesystem::exists( p ) )
                 return false;
             totalSize_ += boost::filesystem::file_size( p );
             return true;
         }
         virtual const char *op() const {
             return "checking size";
         }
         intmax_t totalSize_;
     };
     SizeAccumulator sa;
     _applyOpToDataFiles( database, sa );
     return sa.size();
 }