From: Arvin Schnell Date: Fri, 21 Jun 2013 13:48:28 +0000 (+0200) Subject: - derive ConfigInfo from SysconfigFile X-Git-Tag: v0.1.5~18 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=033edcf1c1343daa58493ac40c00b928310cd27d;p=thirdparty%2Fsnapper.git - derive ConfigInfo from SysconfigFile --- diff --git a/examples/ListAll.cc b/examples/ListAll.cc index ac04419f..53b2e09a 100644 --- a/examples/ListAll.cc +++ b/examples/ListAll.cc @@ -15,7 +15,7 @@ main(int argc, char** argv) list sh; for (list::const_iterator it = c.begin(); it != c.end(); ++it) - sh.push_back(new Snapper(it->config_name)); + sh.push_back(new Snapper(it->getConfigName())); for (list::const_iterator it = sh.begin(); it != sh.end(); ++it) cout << (*it)->configName() << " " << (*it)->subvolumeDir() << " " diff --git a/examples/SnapTest.cc b/examples/SnapTest.cc index 2cd8c2c0..cff002a5 100644 --- a/examples/SnapTest.cc +++ b/examples/SnapTest.cc @@ -41,10 +41,10 @@ main(int argc, char** argv) list c = Snapper::getConfigs(); cout << c.size() << endl; for (list::const_iterator it = c.begin(); it != c.end(); ++it) - cout << it->config_name << " " << it->subvolume << endl; + cout << it->getConfigName() << " " << it->getSubvolume() << endl; if( c.begin()!=c.end() ) - sh = new Snapper(c.front().config_name); + sh = new Snapper(c.front().getConfigName()); if( sh ) { diff --git a/server/Client.cc b/server/Client.cc index 58de0ca3..81fc2bfb 100644 --- a/server/Client.cc +++ b/server/Client.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Novell, Inc. + * Copyright (c) [2012-2013] Novell, Inc. * * All Rights Reserved. * @@ -885,8 +885,8 @@ Client::create_post_snapshot(DBus::Connection& conn, DBus::Message& msg) snap2->setUserdata(userdata); snap2->flushInfo(); - map::const_iterator pos = it->config_info.raw.find("BACKGROUND_COMPARISON"); - if (pos == it->config_info.raw.end() || pos->second == "yes") + bool tmp; + if (it->config_info.getValue("BACKGROUND_COMPARISON", tmp) && tmp) backgrounds.add_task(it, snap1, snap2); DBus::MessageMethodReturn reply(msg); diff --git a/server/MetaSnapper.cc b/server/MetaSnapper.cc index 929afb37..f90a06fa 100644 --- a/server/MetaSnapper.cc +++ b/server/MetaSnapper.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Novell, Inc. + * Copyright (c) [2012-2013] Novell, Inc. * * All Rights Reserved. * @@ -161,39 +161,25 @@ get_group_uids(const char* groupname, vector& uids) MetaSnapper::MetaSnapper(const ConfigInfo& config_info) : config_info(config_info), snapper(NULL) { - map::const_iterator pos1 = config_info.raw.find("ALLOW_USERS"); - if (pos1 != config_info.raw.end()) + vector users; + if (config_info.getValue("ALLOW_USERS", users)) { - string tmp = pos1->second; - boost::trim(tmp, locale::classic()); - if (!tmp.empty()) + for (vector::const_iterator it = users.begin(); it != users.end(); ++it) { - vector users; - boost::split(users, tmp, boost::is_any_of(" \t"), boost::token_compress_on); - for (vector::const_iterator it = users.begin(); it != users.end(); ++it) - { - uid_t tmp; - if (get_user_uid(it->c_str(), tmp)) - uids.push_back(tmp); - } + uid_t tmp; + if (get_user_uid(it->c_str(), tmp)) + uids.push_back(tmp); } } - map::const_iterator pos2 = config_info.raw.find("ALLOW_GROUPS"); - if (pos2 != config_info.raw.end()) + vector groups; + if (config_info.getValue("ALLOW_GROUPS", groups)) { - string tmp = pos2->second; - boost::trim(tmp, locale::classic()); - if (!tmp.empty()) + for (vector::const_iterator it = groups.begin(); it != groups.end(); ++it) { - vector groups; - boost::split(groups, tmp, boost::is_any_of(" \t"), boost::token_compress_on); - for (vector::const_iterator it = groups.begin(); it != groups.end(); ++it) - { - vector tmp; - if (get_group_uids(it->c_str(), tmp)) - uids.insert(uids.end(), tmp.begin(), tmp.end()); - } + vector tmp; + if (get_group_uids(it->c_str(), tmp)) + uids.insert(uids.end(), tmp.begin(), tmp.end()); } } @@ -212,7 +198,7 @@ Snapper* MetaSnapper::getSnapper() { if (!snapper) - snapper = new Snapper(config_info.config_name); + snapper = new Snapper(config_info.getConfigName()); update_use_time(); diff --git a/server/MetaSnapper.h b/server/MetaSnapper.h index 41d2c1e6..955fe6f0 100644 --- a/server/MetaSnapper.h +++ b/server/MetaSnapper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Novell, Inc. + * Copyright (c) [2012-2013] Novell, Inc. * * All Rights Reserved. * @@ -89,7 +89,7 @@ public: MetaSnapper(const ConfigInfo& config_info); ~MetaSnapper(); - const string& configName() const { return config_info.config_name; } + const string& configName() const { return config_info.getConfigName(); } const ConfigInfo config_info; diff --git a/server/Types.cc b/server/Types.cc index 76e67d1d..1aa23d19 100644 --- a/server/Types.cc +++ b/server/Types.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 Novell, Inc. + * Copyright (c) [2012-2013] Novell, Inc. * * All Rights Reserved. * @@ -34,7 +34,7 @@ namespace DBus operator<<(Hoho& hoho, const ConfigInfo& data) { hoho.open_struct(); - hoho << data.config_name << data.subvolume << data.raw; + hoho << data.getConfigName() << data.getSubvolume() << data.getAllValues(); hoho.close_struct(); return hoho; } diff --git a/snapper/Makefile.am b/snapper/Makefile.am index 5296246b..c68cdd0b 100644 --- a/snapper/Makefile.am +++ b/snapper/Makefile.am @@ -63,5 +63,6 @@ pkginclude_HEADERS = \ Snapshot.h \ File.h \ Comparison.h \ + AsciiFile.h \ Exception.h \ Logger.h diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 1bb47630..656634f6 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) [2011-2012] Novell, Inc. + * Copyright (c) [2011-2013] Novell, Inc. * * All Rights Reserved. * @@ -47,6 +47,13 @@ namespace snapper using namespace std; + ConfigInfo::ConfigInfo(const string& config_name) + : SysconfigFile(CONFIGSDIR "/" + config_name), config_name(config_name), subvolume("/") + { + getValue("SUBVOLUME", subvolume); + } + + Snapper::Snapper(const string& config_name, bool disable_filters) : config_name(config_name), config(NULL), subvolume("/"), filesystem(NULL), snapshots(this) @@ -185,14 +192,7 @@ namespace snapper ConfigInfo Snapper::getConfig(const string& config_name) { - SysconfigFile config(CONFIGSDIR "/" + config_name); - - string subvolume = "/"; - config.getValue("SUBVOLUME", subvolume); - - map raw = config.getAllValues(); - - return ConfigInfo(config_name, subvolume, raw); + return ConfigInfo(config_name); } @@ -253,7 +253,7 @@ namespace snapper list configs = getConfigs(); for (list::const_iterator it = configs.begin(); it != configs.end(); ++it) { - if (it->subvolume == subvolume) + if (it->getSubvolume() == subvolume) { throw CreateConfigFailedException("subvolume already covered"); } diff --git a/snapper/Snapper.h b/snapper/Snapper.h index 093ecaf8..480881aa 100644 --- a/snapper/Snapper.h +++ b/snapper/Snapper.h @@ -1,5 +1,5 @@ /* - * Copyright (c) [2011-2012] Novell, Inc. + * Copyright (c) [2011-2013] Novell, Inc. * * All Rights Reserved. * @@ -28,6 +28,7 @@ #include #include "snapper/Snapshot.h" +#include "snapper/AsciiFile.h" namespace snapper @@ -35,21 +36,23 @@ namespace snapper using std::vector; - class SysconfigFile; class Filesystem; class SDir; - struct ConfigInfo + struct ConfigInfo : public SysconfigFile { - ConfigInfo(const string& config_name, const string& subvolume, - const map& raw) - : config_name(config_name), subvolume(subvolume), raw(raw) {} + explicit ConfigInfo(const string& config_name); + + const string& getConfigName() const { return config_name; } + const string& getSubvolume() const { return subvolume; } + + private: + + const string config_name; - string config_name; string subvolume; - map raw; };