mirror of https://github.com/vitalif/zbackup
Make keywords non-static for #48
As suggested on https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64830
parent
24303c1309
commit
9cae833045
218
config.cc
218
config.cc
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) 2012-2014 Konstantin Isakov <ikm@zbackup.org> and ZBackup contributors, see CONTRIBUTORS
|
// Copyright (c) 2012-2014 Konstantin Isakov <ikm@zbackup.org> and ZBackup contributors, see CONTRIBUTORS
|
||||||
// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE
|
// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include "config.hh"
|
#include "config.hh"
|
||||||
#include "ex.hh"
|
#include "ex.hh"
|
||||||
#include "debug.hh"
|
#include "debug.hh"
|
||||||
|
@ -36,125 +37,125 @@
|
||||||
|
|
||||||
DEF_EX_STR( exInvalidThreadsValue, "Invalid threads value specified:", std::exception )
|
DEF_EX_STR( exInvalidThreadsValue, "Invalid threads value specified:", std::exception )
|
||||||
|
|
||||||
namespace ConfigHelper {
|
void Config::prefillKeywords()
|
||||||
Config defaultConfig;
|
|
||||||
|
|
||||||
/* Textual representations of the tokens. */
|
|
||||||
|
|
||||||
static struct
|
|
||||||
{
|
{
|
||||||
const char * name;
|
/* Textual representations of the tokens. */
|
||||||
const Config::OpCodes opcode;
|
|
||||||
const Config::OptionType type;
|
|
||||||
const char * description;
|
|
||||||
const string defaultValue;
|
|
||||||
} keywords[] = {
|
|
||||||
// Storable options
|
|
||||||
{
|
|
||||||
"chunk.max_size",
|
|
||||||
Config::oChunk_max_size,
|
|
||||||
Config::Storable,
|
|
||||||
"Maximum chunk size used when storing chunks\n"
|
|
||||||
"Affects deduplication ratio directly"
|
|
||||||
//"Default is %s",
|
|
||||||
//Utils::numberToString( defaultConfig.GET_STORABLE( chunk, max_size ) )
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"bundle.max_payload_size",
|
|
||||||
Config::oBundle_max_payload_size,
|
|
||||||
Config::Storable,
|
|
||||||
"Maximum number of bytes a bundle can hold. Only real chunk bytes are\n"
|
|
||||||
"counted, not metadata. Any bundle should be able to contain at least\n"
|
|
||||||
"one arbitrary single chunk, so this should not be smaller than\n"
|
|
||||||
"chunk.max_size"
|
|
||||||
//"Default is %s",
|
|
||||||
//Utils::numberToString( defaultConfig.GET_STORABLE( bundle, max_payload_size ) )
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"bundle.compression_method",
|
|
||||||
Config::oBundle_compression_method,
|
|
||||||
Config::Storable,
|
|
||||||
"Compression method for new bundles"
|
|
||||||
//"Default is %s",
|
|
||||||
//defaultConfig.GET_STORABLE( bundle, compression_method )
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"lzma.compression_level",
|
|
||||||
Config::oLZMA_compression_level,
|
|
||||||
Config::Storable,
|
|
||||||
"Compression level for new LZMA-compressed files\n"
|
|
||||||
"Valid values: 0-19 (values over 9 enables extreme mode)"
|
|
||||||
//"Default is %s",
|
|
||||||
//Utils::numberToString( defaultConfig.GET_STORABLE( lzma, compression_level ) )
|
|
||||||
},
|
|
||||||
|
|
||||||
// Shortcuts for storable options
|
Keyword defaultKeywords[] = {
|
||||||
{
|
// Storable options
|
||||||
"compression",
|
{
|
||||||
Config::oBundle_compression_method,
|
"chunk.max_size",
|
||||||
Config::Storable,
|
Config::oChunk_max_size,
|
||||||
"Shortcut for bundle.compression_method"
|
Config::Storable,
|
||||||
//"Default is %s",
|
"Maximum chunk size used when storing chunks\n"
|
||||||
//defaultConfig.GET_STORABLE( bundle, compression_method )
|
"Affects deduplication ratio directly\n"
|
||||||
},
|
"Default is %s",
|
||||||
|
Utils::numberToString( GET_STORABLE( chunk, max_size ) )
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bundle.max_payload_size",
|
||||||
|
Config::oBundle_max_payload_size,
|
||||||
|
Config::Storable,
|
||||||
|
"Maximum number of bytes a bundle can hold. Only real chunk bytes are\n"
|
||||||
|
"counted, not metadata. Any bundle should be able to contain at least\n"
|
||||||
|
"one arbitrary single chunk, so this should not be smaller than\n"
|
||||||
|
"chunk.max_size\n"
|
||||||
|
"Default is %s",
|
||||||
|
Utils::numberToString( GET_STORABLE( bundle, max_payload_size ) )
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"bundle.compression_method",
|
||||||
|
Config::oBundle_compression_method,
|
||||||
|
Config::Storable,
|
||||||
|
"Compression method for new bundles\n"
|
||||||
|
"Default is %s",
|
||||||
|
GET_STORABLE( bundle, compression_method )
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"lzma.compression_level",
|
||||||
|
Config::oLZMA_compression_level,
|
||||||
|
Config::Storable,
|
||||||
|
"Compression level for new LZMA-compressed files\n"
|
||||||
|
"Valid values: 0-19 (values over 9 enables extreme mode)\n"
|
||||||
|
"Default is %s",
|
||||||
|
Utils::numberToString( GET_STORABLE( lzma, compression_level ) )
|
||||||
|
},
|
||||||
|
|
||||||
// Runtime options
|
// Shortcuts for storable options
|
||||||
{
|
{
|
||||||
"threads",
|
"compression",
|
||||||
Config::oRuntime_threads,
|
Config::oBundle_compression_method,
|
||||||
Config::Runtime,
|
Config::Storable,
|
||||||
"Maximum number of compressor threads to use in backup process\n"
|
"Shortcut for bundle.compression_method\n"
|
||||||
"Default is %s on your system",
|
"Default is %s",
|
||||||
Utils::numberToString( defaultConfig.runtime.threads )
|
GET_STORABLE( bundle, compression_method )
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"cache-size",
|
|
||||||
Config::oRuntime_cacheSize,
|
|
||||||
Config::Runtime,
|
|
||||||
"Cache size to use in restore process\n"
|
|
||||||
"Affects restore process speed directly\n"
|
|
||||||
VALID_SUFFIXES
|
|
||||||
"Default is %sMiB",
|
|
||||||
Utils::numberToString( defaultConfig.runtime.cacheSize / 1024 / 1024 )
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"exchange",
|
|
||||||
Config::oRuntime_exchange,
|
|
||||||
Config::Runtime,
|
|
||||||
"Data to exchange between repositories in import/export process\n"
|
|
||||||
"Can be specified multiple times\n"
|
|
||||||
"Valid values:\n"
|
|
||||||
"backups - exchange backup instructions (files in backups/ directory)\n"
|
|
||||||
"bundles - exchange bundles with data (files in bunles/ directory)\n"
|
|
||||||
"index - exchange indicies of chunks (files in index/ directory)\n"
|
|
||||||
"No default value, you should specify it explicitly"
|
|
||||||
},
|
|
||||||
|
|
||||||
{ NULL, Config::oBadOption, Config::None }
|
// Runtime options
|
||||||
};
|
{
|
||||||
|
"threads",
|
||||||
|
Config::oRuntime_threads,
|
||||||
|
Config::Runtime,
|
||||||
|
"Maximum number of compressor threads to use in backup process\n"
|
||||||
|
"Default is %s on your system",
|
||||||
|
Utils::numberToString( runtime.threads )
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cache-size",
|
||||||
|
Config::oRuntime_cacheSize,
|
||||||
|
Config::Runtime,
|
||||||
|
"Cache size to use in restore process\n"
|
||||||
|
"Affects restore process speed directly\n"
|
||||||
|
VALID_SUFFIXES
|
||||||
|
"Default is %sMiB",
|
||||||
|
Utils::numberToString( runtime.cacheSize / 1024 / 1024 )
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"exchange",
|
||||||
|
Config::oRuntime_exchange,
|
||||||
|
Config::Runtime,
|
||||||
|
"Data to exchange between repositories in import/export process\n"
|
||||||
|
"Can be specified multiple times\n"
|
||||||
|
"Valid values:\n"
|
||||||
|
"backups - exchange backup instructions (files in backups/ directory)\n"
|
||||||
|
"bundles - exchange bundles with data (files in bunles/ directory)\n"
|
||||||
|
"index - exchange indicies of chunks (files in index/ directory)\n"
|
||||||
|
"No default value, you should specify it explicitly"
|
||||||
|
},
|
||||||
|
|
||||||
|
{ "", Config::oBadOption, Config::None }
|
||||||
|
};
|
||||||
|
|
||||||
|
keywords = new Keyword[ sizeof( defaultKeywords) / sizeof( Keyword ) ];
|
||||||
|
std::copy( defaultKeywords, defaultKeywords +
|
||||||
|
sizeof( defaultKeywords) / sizeof( Keyword ), keywords );
|
||||||
|
cleanup_keywords = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::~Config()
|
Config::~Config()
|
||||||
{
|
{
|
||||||
// prevent memleak
|
// prevent memleaks
|
||||||
if ( want_cleanup )
|
// TODO: use sptr
|
||||||
|
if ( cleanup_storable )
|
||||||
delete storable;
|
delete storable;
|
||||||
|
if ( cleanup_keywords )
|
||||||
|
delete[] keywords;
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::Config():
|
Config::Config():
|
||||||
want_cleanup( false )
|
cleanup_storable( true )
|
||||||
{
|
{
|
||||||
ConfigInfo * configInfo = new ConfigInfo;
|
storable = new ConfigInfo;
|
||||||
storable = configInfo;
|
prefillKeywords();
|
||||||
dPrintf( "%s is instantiated and initialized with default values\n",
|
dPrintf( "%s is instantiated and initialized with default values\n",
|
||||||
__CLASS );
|
__CLASS );
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::Config( ConfigInfo * configInfo ):
|
Config::Config( ConfigInfo * configInfo ):
|
||||||
want_cleanup( false )
|
cleanup_storable( false )
|
||||||
{
|
{
|
||||||
storable = configInfo;
|
storable = configInfo;
|
||||||
|
prefillKeywords();
|
||||||
dPrintf( "%s is instantiated and initialized with supplied ConfigInfo\n",
|
dPrintf( "%s is instantiated and initialized with supplied ConfigInfo\n",
|
||||||
__CLASS );
|
__CLASS );
|
||||||
}
|
}
|
||||||
|
@ -164,24 +165,25 @@ Config::Config( const Config & configIn, ConfigInfo * configInfo )
|
||||||
configInfo->MergeFrom( *configIn.storable );
|
configInfo->MergeFrom( *configIn.storable );
|
||||||
*this = configIn;
|
*this = configIn;
|
||||||
storable = configInfo;
|
storable = configInfo;
|
||||||
want_cleanup = false;
|
cleanup_storable = false;
|
||||||
|
cleanup_keywords = false;
|
||||||
dPrintf( "%s is instantiated and initialized with supplied values\n",
|
dPrintf( "%s is instantiated and initialized with supplied values\n",
|
||||||
__CLASS );
|
__CLASS );
|
||||||
}
|
}
|
||||||
|
|
||||||
Config::OpCodes Config::parseToken( const char * option, const OptionType type )
|
Config::OpCodes Config::parseToken( const char * option, const OptionType type )
|
||||||
{
|
{
|
||||||
for ( u_int i = 0; ConfigHelper::keywords[ i ].name; i++ )
|
for ( u_int i = 0; !keywords[ i ].name.empty(); i++ )
|
||||||
{
|
{
|
||||||
if ( strcasecmp( option, ConfigHelper::keywords[ i ].name ) == 0 )
|
if ( strcasecmp( option, keywords[ i ].name.c_str() ) == 0 )
|
||||||
{
|
{
|
||||||
if ( ConfigHelper::keywords[ i ].type != type )
|
if ( keywords[ i ].type != type )
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Invalid option type specified for %s\n", option );
|
fprintf( stderr, "Invalid option type specified for %s\n", option );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ConfigHelper::keywords[ i ].opcode;
|
return keywords[ i ].opcode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,14 +467,14 @@ void Config::showHelp( const OptionType type )
|
||||||
"show this message\n"
|
"show this message\n"
|
||||||
"", ( type == Runtime ? "runtime" : ( type == Storable ? "storable" : "" ) ) );
|
"", ( type == Runtime ? "runtime" : ( type == Storable ? "storable" : "" ) ) );
|
||||||
|
|
||||||
for ( u_int i = 0; ConfigHelper::keywords[ i ].name; i++ )
|
for ( u_int i = 0; !keywords[ i ].name.empty(); i++ )
|
||||||
{
|
{
|
||||||
if ( ConfigHelper::keywords[ i ].type != type )
|
if ( keywords[ i ].type != type )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
fprintf( stderr, "\n== %s ==\n", ConfigHelper::keywords[ i ].name );
|
fprintf( stderr, "\n== %s ==\n", keywords[ i ].name.c_str() );
|
||||||
fprintf( stderr, ConfigHelper::keywords[ i ].description,
|
fprintf( stderr, keywords[ i ].description.c_str(),
|
||||||
ConfigHelper::keywords[ i ].defaultValue.c_str() );
|
keywords[ i ].defaultValue.c_str() );
|
||||||
fprintf( stderr, "\n" );
|
fprintf( stderr, "\n" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
22
config.hh
22
config.hh
|
@ -4,6 +4,7 @@
|
||||||
#ifndef CONFIG_HH_INCLUDED
|
#ifndef CONFIG_HH_INCLUDED
|
||||||
#define CONFIG_HH_INCLUDED
|
#define CONFIG_HH_INCLUDED
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <google/protobuf/text_format.h>
|
#include <google/protobuf/text_format.h>
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::bitset;
|
using std::bitset;
|
||||||
|
using std::vector;
|
||||||
|
|
||||||
class Config
|
class Config
|
||||||
{
|
{
|
||||||
|
@ -67,14 +69,14 @@ public:
|
||||||
|
|
||||||
static bool parseProto( const string &, google::protobuf::Message * );
|
static bool parseProto( const string &, google::protobuf::Message * );
|
||||||
|
|
||||||
static void showHelp( const OptionType );
|
|
||||||
|
|
||||||
static string toString( google::protobuf::Message const & );
|
static string toString( google::protobuf::Message const & );
|
||||||
|
|
||||||
// Print configuration to screen
|
// Print configuration to screen
|
||||||
static void show( const ConfigInfo & );
|
static void show( const ConfigInfo & );
|
||||||
void show();
|
void show();
|
||||||
|
|
||||||
|
void showHelp( const OptionType );
|
||||||
|
|
||||||
OpCodes parseToken( const char *, const OptionType );
|
OpCodes parseToken( const char *, const OptionType );
|
||||||
bool parseOrValidate( const char *, const OptionType, bool validate = false );
|
bool parseOrValidate( const char *, const OptionType, bool validate = false );
|
||||||
|
|
||||||
|
@ -88,7 +90,21 @@ public:
|
||||||
RuntimeConfig runtime;
|
RuntimeConfig runtime;
|
||||||
ConfigInfo * storable;
|
ConfigInfo * storable;
|
||||||
private:
|
private:
|
||||||
bool want_cleanup;
|
struct Keyword
|
||||||
|
{
|
||||||
|
string name;
|
||||||
|
Config::OpCodes opcode;
|
||||||
|
Config::OptionType type;
|
||||||
|
string description;
|
||||||
|
string defaultValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
Keyword * keywords;
|
||||||
|
|
||||||
|
bool cleanup_storable;
|
||||||
|
bool cleanup_keywords;
|
||||||
|
|
||||||
|
void prefillKeywords();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -418,7 +418,7 @@ int main( int argc, char *argv[] )
|
||||||
|
|
||||||
if ( strcmp( option, "help" ) == 0 )
|
if ( strcmp( option, "help" ) == 0 )
|
||||||
{
|
{
|
||||||
Config::showHelp( optionType );
|
config.showHelp( optionType );
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue