]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- allow to set root directory
authorArvin Schnell <aschnell@suse.de>
Mon, 14 Feb 2011 16:19:01 +0000 (17:19 +0100)
committerArvin Schnell <aschnell@suse.de>
Mon, 14 Feb 2011 16:19:01 +0000 (17:19 +0100)
snapper/Factory.cc
snapper/Factory.h
snapper/Snapper.cc
snapper/Snapper.h
tools/snapper.cc

index 1b24d8a5957355409c0b6abc7fbb70f9c0929043..1320b99f9060b39e9822e8716e3f527d402d0b35 100644 (file)
@@ -33,10 +33,10 @@ namespace snapper
 
 
     Snapper*
-    createSnapper()
+    createSnapper(const string& root)
     {
        assert(!haha.get());
-       haha.reset(new Snapper);
+       haha.reset(new Snapper(root));
        return haha.get();
     }
 
index 3eb3bdb19e9623deacfef23aca8ccecd0581c1d6..7ac61940f883a5c6647b5f574d88106220ca2b75 100644 (file)
 #define FACTORY_H
 
 
+#include <string>
+
+
 namespace snapper
 {
+    using std::string;
+
 
     class Snapper;
 
 
     // Only one Snapper can be created at a time.
 
-    Snapper* createSnapper();
+    Snapper* createSnapper(const string& root = "/");
 
     void deleteSnapper(Snapper*);
 
index ea5c6a7cdb5438a463b108c82bed49b86d2dd71c..d3fbe53bed3bb13b333469e0541c07606c004f5c 100644 (file)
@@ -40,8 +40,8 @@ namespace snapper
     using namespace std;
 
 
-    Snapper::Snapper()
-       : snapshots(this), files(this), compare_callback(NULL)
+    Snapper::Snapper(const string& root)
+       : root(root), snapshots(this), files(this), compare_callback(NULL)
     {
        y2mil("Snapper constructor");
 
@@ -59,7 +59,7 @@ namespace snapper
     string
     Snapper::rootDir() const
     {
-       return "/";
+       return root;
     }
 
 
index 7184d56b6c3be3894ac09b2f44c79bb9381e814e..5518f54079bed30d62b7ae00a3c9a1eb276ccc4f 100644 (file)
@@ -45,7 +45,7 @@ namespace snapper
     {
     public:
 
-       Snapper();
+       Snapper(const string& root = "/");
        ~Snapper();
 
        string rootDir() const;
@@ -79,6 +79,8 @@ namespace snapper
 
     private:
 
+       const string root;
+
        Snapshots snapshots;
 
        Snapshots::const_iterator snapshot1;
index 3b0faa5bf7bfd8b6d30086cc3cfc186b66045327..5a524e901b9f118018dff48ad5fc41e2b240a2bd 100644 (file)
@@ -25,6 +25,7 @@ map<string, cmd_fnc> cmds;
 GetOpts getopts;
 
 bool quiet = false;
+string root = "/";
 
 Snapper* sh = NULL;
 
@@ -387,6 +388,7 @@ command_help()
     cout << _("    Global options:") << endl
         << _("\t--quiet, -q\t\t\tSuppress normal output.") << endl
         << _("\t--table-style, -s <style>\tTable style (integer).") << endl
+        << _("\t--root, -r <path>\t\tSet root directory.") << endl
         << endl;
 
     help_list();
@@ -425,6 +427,7 @@ main(int argc, char** argv)
     const struct option options[] = {
        { "quiet",              no_argument,            0,      'q' },
        { "table-style",        required_argument,      0,      's' },
+       { "root",               required_argument,      0,      'r' },
        { 0, 0, 0, 0 }
     };
 
@@ -465,7 +468,10 @@ main(int argc, char** argv)
        Table::defaultStyle = (TableLineStyle) s;
     }
 
-    sh = createSnapper();
+    if ((it = opts.find("root")) != opts.end())
+       root = it->second;
+
+    sh = createSnapper(root);
 
     if (!quiet)
        sh->setCompareCallback(&compare_callback_impl);