mirror of https://github.com/vitalif/zbackup
A little bit more engineering for Config
parent
2f736764ac
commit
4a7314cb7e
|
@ -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,
|
||||
|
|
21
config.cc
21
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;
|
||||
|
|
18
config.hh
18
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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue