]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- derive ConfigInfo from SysconfigFile
authorArvin Schnell <aschnell@suse.de>
Fri, 21 Jun 2013 13:48:28 +0000 (15:48 +0200)
committerArvin Schnell <aschnell@suse.de>
Fri, 21 Jun 2013 13:48:28 +0000 (15:48 +0200)
examples/ListAll.cc
examples/SnapTest.cc
server/Client.cc
server/MetaSnapper.cc
server/MetaSnapper.h
server/Types.cc
snapper/Makefile.am
snapper/Snapper.cc
snapper/Snapper.h

index ac04419fc83e3e70597c75c6b7dbe5e77e882245..53b2e09add83bb4b14009ccdb2c1827cee40187e 100644 (file)
@@ -15,7 +15,7 @@ main(int argc, char** argv)
     list<Snapper*> sh;
 
     for (list<ConfigInfo>::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<Snapper*>::const_iterator it = sh.begin(); it != sh.end(); ++it)
        cout << (*it)->configName() << " " << (*it)->subvolumeDir() << " "
index 2cd8c2c0ff5a2124716d4b894096ad6dff46b185..cff002a527b486a19eb88b5a29e0126e2f030521 100644 (file)
@@ -41,10 +41,10 @@ main(int argc, char** argv)
     list<ConfigInfo> c = Snapper::getConfigs();
     cout << c.size() << endl;
     for (list<ConfigInfo>::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 )
        {
index 58de0ca3bd394492458a1de5c48a0fbd7e4eb957..81fc2bfb85a393f4522c842ab1276df4d38d40bf 100644 (file)
@@ -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<string, string>::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);
index 929afb37bc1444737a5b13160f226c951cca3ab9..f90a06fa1b21a4738d8bd4397bab747287b0efa9 100644 (file)
@@ -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<uid_t>& uids)
 MetaSnapper::MetaSnapper(const ConfigInfo& config_info)
     : config_info(config_info), snapper(NULL)
 {
-    map<string, string>::const_iterator pos1 = config_info.raw.find("ALLOW_USERS");
-    if (pos1 != config_info.raw.end())
+    vector<string> users;
+    if (config_info.getValue("ALLOW_USERS", users))
     {
-       string tmp = pos1->second;
-       boost::trim(tmp, locale::classic());
-       if (!tmp.empty())
+       for (vector<string>::const_iterator it = users.begin(); it != users.end(); ++it)
        {
-           vector<string> users;
-           boost::split(users, tmp, boost::is_any_of(" \t"), boost::token_compress_on);
-           for (vector<string>::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<string, string>::const_iterator pos2 = config_info.raw.find("ALLOW_GROUPS");
-    if (pos2 != config_info.raw.end())
+    vector<string> groups;
+    if (config_info.getValue("ALLOW_GROUPS", groups))
     {
-       string tmp = pos2->second;
-       boost::trim(tmp, locale::classic());
-       if (!tmp.empty())
+       for (vector<string>::const_iterator it = groups.begin(); it != groups.end(); ++it)
        {
-           vector<string> groups;
-           boost::split(groups, tmp, boost::is_any_of(" \t"), boost::token_compress_on);
-           for (vector<string>::const_iterator it = groups.begin(); it != groups.end(); ++it)
-           {
-               vector<uid_t> tmp;
-               if (get_group_uids(it->c_str(), tmp))
-                   uids.insert(uids.end(), tmp.begin(), tmp.end());
-           }
+           vector<uid_t> 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();
 
index 41d2c1e6af56c21a1d5bc8ec21c2b69d20b409cf..955fe6f0c5e5ab3c25022c25f669f33ca2a819cb 100644 (file)
@@ -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;
 
index 76e67d1db3ea4542413cd1c08dea877f15ddb187..1aa23d1957ba16730cb76f0e9995d045fce0f9b0 100644 (file)
@@ -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;
     }
index 5296246bae327cbc144336ee53df09756fb9d56e..c68cdd0b38698842fd0df2f01e6b580ec0ad9efd 100644 (file)
@@ -63,5 +63,6 @@ pkginclude_HEADERS =                                  \
        Snapshot.h                                      \
        File.h                                          \
        Comparison.h                                    \
+       AsciiFile.h                                     \
        Exception.h                                     \
        Logger.h
index 1bb47630d1d4015e4435ad348d2407ef63aeb8ad..656634f639de4045fc21aef26bc8be20903ae4b8 100644 (file)
@@ -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<string, string> raw = config.getAllValues();
-
-       return ConfigInfo(config_name, subvolume, raw);
+       return ConfigInfo(config_name);
     }
 
 
@@ -253,7 +253,7 @@ namespace snapper
        list<ConfigInfo> configs = getConfigs();
        for (list<ConfigInfo>::const_iterator it = configs.begin(); it != configs.end(); ++it)
        {
-           if (it->subvolume == subvolume)
+           if (it->getSubvolume() == subvolume)
            {
                throw CreateConfigFailedException("subvolume already covered");
            }
index 093ecaf83d495751e9628d2d73bb0ca0ffd28a22..480881aa41bc2b547021908f546ce77a29b8cc30 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) [2011-2012] Novell, Inc.
+ * Copyright (c) [2011-2013] Novell, Inc.
  *
  * All Rights Reserved.
  *
@@ -28,6 +28,7 @@
 #include <boost/noncopyable.hpp>
 
 #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<string, string>& 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<string, string> raw;
     };