diff --git a/chunk_index.cc b/chunk_index.cc index 34c4d03..5220004 100644 --- a/chunk_index.cc +++ b/chunk_index.cc @@ -105,10 +105,10 @@ ChunkIndex::ChunkIndex( EncryptionKey const & key, TmpMgr & tmpMgr, key( key ), tmpMgr( tmpMgr ), indexPath( indexPath ), storage( 65536, 1 ), lastBundleId( NULL ) { - dPrintf( "Chunk index (%s) instantiated and initialized, hasKey: %s\n", indexPath.c_str(), - key.hasKey() ? "true" : "false" ); if ( !prohibitChunkIndexLoading ) loadIndex( *this ); + dPrintf( "Chunk index for %s is instantiated and initialized, hasKey: %s\n", + indexPath.c_str(), key.hasKey() ? "true" : "false" ); } Bundle::Id const * ChunkIndex::findChunk( ChunkId::RollingHashPart rollingHash, diff --git a/config.cc b/config.cc index 71c8fc1..1e299c7 100644 --- a/config.cc +++ b/config.cc @@ -101,6 +101,24 @@ static struct } +Config::Config() +{ + ConfigInfo * configInfo = new ConfigInfo; + storable = configInfo; + dPrintf( "Config is instantiated and initialized with default values\n" ); +} +Config::Config( ConfigInfo * configInfo ) +{ + storable = configInfo; + dPrintf( "Config is instantiated and initialized with supplied ConfigInfo\n" ); +} +Config::Config( const Config & configIn, ConfigInfo * configInfo ) +{ + *this = configIn; + storable = configInfo; + dPrintf( "Config is instantiated and initialized with supplied values\n" ); +} + Config::OpCodes Config::parseToken( const char * option, const OptionType type ) { for ( u_int i = 0; ConfigHelper::keywords[ i ].name; i++ ) @@ -190,6 +208,9 @@ bool Config::parseOption( const char * option, const OptionType type ) return false; } + SET_STORABLE( bundle, compression_method, optionValue ); + dPrintf( "storable[bundle][compression_method] = %s\n", GET_STORABLE( bundle, compression_method ).c_str() ); + return true; /* NOTREACHED */ break; diff --git a/config.hh b/config.hh index ff7cc26..f8dda6c 100644 --- a/config.hh +++ b/config.hh @@ -11,6 +11,14 @@ #include "mt.hh" #include "backup_exchanger.hh" +#define SET_STORABLE( storage, property, value ) (\ +{\ + dPrintf( "storable->mutable_"#storage"()->set_"#property"( "#value" )\n" ); \ + storable->mutable_##storage()->set_##property( value ); \ +}) + +#define GET_STORABLE( storage, property ) storable->storage().property() + using std::string; using std::bitset; @@ -31,8 +39,6 @@ public: } }; - RuntimeConfig runtime; - enum OptionType { Runtime, @@ -67,8 +73,14 @@ public: bool parseOption( const char * option, const OptionType ); string toString( google::protobuf::Message const & message ); + + Config( const Config &, ConfigInfo * ); + Config( ConfigInfo * ); + Config(); + + RuntimeConfig runtime; + ConfigInfo * storable; private: - ConfigInfo storableConfig; }; #endif diff --git a/zbackup.cc b/zbackup.cc index a3486c1..9c7a37f 100644 --- a/zbackup.cc +++ b/zbackup.cc @@ -394,7 +394,7 @@ int main( int argc, char *argv[] ) else if ( strcmp( argv[ x ], "--compression" ) == 0 && x + 1 < argc ) { - fprintf( stderr, "%s is deprecated, use -O bundle.compression_method instead\n", argv[ x ] ); + fprintf( stderr, "%s is deprecated, use -o bundle.compression_method instead\n", argv[ x ] ); deprecated.assign( argv[ x ] + 2 ); deprecated.append( "=" ); deprecated.append( argv[ x + 1 ] ); @@ -654,7 +654,7 @@ invalid_option: if ( args.size() > 2 && strcmp( args[ fieldAction ], "edit" ) == 0 ) { ZBackupBase zbb( ZBackupBase::deriveStorageDirFromBackupsFile( args[ fieldStorage ], true ), - passwords[ 0 ] ); + passwords[ 0 ], true ); if ( zbb.editConfigInteractively() ) zbb.saveExtendedStorageInfo(); } @@ -662,13 +662,13 @@ invalid_option: if ( args.size() > 2 && strcmp( args[ fieldAction ], "set" ) == 0 ) { ZBackupBase zbb( ZBackupBase::deriveStorageDirFromBackupsFile( args[ fieldStorage ], true ), - passwords[ 0 ] ); + passwords[ 0 ], true ); // -o ... like sysctl -w } else { ZBackupBase zbb( ZBackupBase::deriveStorageDirFromBackupsFile( args[ fieldStorage ], true ), - passwords[ 0 ] ); + passwords[ 0 ], true ); zbb.showConfig(); } } diff --git a/zbackup.proto b/zbackup.proto index 3a2430d..62df774 100644 --- a/zbackup.proto +++ b/zbackup.proto @@ -59,6 +59,7 @@ message BundleConfigInfo optional string compression_method = 3 [default = "lzma"]; } +// Storable config values should always have default values message ConfigInfo { required ChunkConfigInfo chunk = 1; diff --git a/zbackup_base.cc b/zbackup_base.cc index dbd8154..b98d332 100644 --- a/zbackup_base.cc +++ b/zbackup_base.cc @@ -63,10 +63,12 @@ ZBackupBase::ZBackupBase( string const & storageDir, string const & password ): &storageInfo.encryption_key() : 0 ), extendedStorageInfo( loadExtendedStorageInfo( encryptionkey ) ), tmpMgr( getTmpPath() ), - chunkIndex( encryptionkey, tmpMgr, getIndexPath(), false ) + chunkIndex( encryptionkey, tmpMgr, getIndexPath(), false ), + config( extendedStorageInfo.mutable_config() ) { propagateUpdate(); - dPrintf("%s repo instantiated and initialized\n", storageDir.c_str() ); + dPrintf("ZBackupBase for %s is instantiated and initialized\n", + storageDir.c_str() ); } ZBackupBase::ZBackupBase( string const & storageDir, string const & password, @@ -77,10 +79,11 @@ ZBackupBase::ZBackupBase( string const & storageDir, string const & password, extendedStorageInfo( loadExtendedStorageInfo( encryptionkey ) ), tmpMgr( getTmpPath() ), chunkIndex( encryptionkey, tmpMgr, getIndexPath(), false ), - config( configIn ) + config( configIn, extendedStorageInfo.mutable_config() ) { propagateUpdate(); - dPrintf("%s repo instantiated and initialized\n", storageDir.c_str() ); + dPrintf("ZBackupBase for %s is instantiated and initialized\n", + storageDir.c_str() ); } ZBackupBase::ZBackupBase( string const & storageDir, string const & password, @@ -90,10 +93,12 @@ ZBackupBase::ZBackupBase( string const & storageDir, string const & password, &storageInfo.encryption_key() : 0 ), extendedStorageInfo( loadExtendedStorageInfo( encryptionkey ) ), tmpMgr( getTmpPath() ), - chunkIndex( encryptionkey, tmpMgr, getIndexPath(), prohibitChunkIndexLoading ) + chunkIndex( encryptionkey, tmpMgr, getIndexPath(), prohibitChunkIndexLoading ), + config( extendedStorageInfo.mutable_config() ) { propagateUpdate(); - dPrintf("%s repo instantiated and initialized\n", storageDir.c_str() ); + dPrintf("ZBackupBase for %s is instantiated and initialized\n", + storageDir.c_str() ); } ZBackupBase::ZBackupBase( string const & storageDir, string const & password, @@ -104,10 +109,11 @@ ZBackupBase::ZBackupBase( string const & storageDir, string const & password, extendedStorageInfo( loadExtendedStorageInfo( encryptionkey ) ), tmpMgr( getTmpPath() ), chunkIndex( encryptionkey, tmpMgr, getIndexPath(), prohibitChunkIndexLoading ), - config( configIn ) + config( configIn, extendedStorageInfo.mutable_config() ) { propagateUpdate(); - dPrintf("%s repo instantiated and initialized\n", storageDir.c_str() ); + dPrintf("ZBackupBase for %s is instantiated and initialized\n", + storageDir.c_str() ); } void ZBackupBase::propagateUpdate() @@ -393,7 +399,7 @@ end: void ZBackupBase::showConfig() { - printf( "%s", config.toString( extendedStorageInfo.config() ).c_str() ); + printf( "%s", config.toString( *config.storable ).c_str() ); } bool ZBackupBase::editConfigInteractively()