]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- added option to set fstype
authorArvin Schnell <aschnell@suse.de>
Tue, 2 Aug 2011 12:20:03 +0000 (14:20 +0200)
committerArvin Schnell <aschnell@suse.de>
Tue, 2 Aug 2011 12:20:03 +0000 (14:20 +0200)
snapper/Snapper.cc
snapper/Snapper.h
tools/snapper.cc

index c731fcc41599a9cd2f5a6673d71863a5a3182689..ee5b388381326df251d189925cd874f67db99354 100644 (file)
@@ -542,14 +542,12 @@ namespace snapper
 
     void
     Snapper::addConfig(const string& config_name, const string& subvolume,
-                      const string& template_name)
+                      const string& fstype, const string& template_name)
     {
        y2mil("Snapper add-config");
        y2mil("libsnapper version " VERSION);
        y2mil("config_name:" << config_name << " subvolume:" << subvolume <<
-             " template_name:" << template_name);
-
-       string fstype = "ext4";
+             " fstype:" << fstype << " template_name:" << template_name);
 
        if (config_name.empty() || config_name.find_first_of(" \t") != string::npos)
        {
@@ -566,6 +564,16 @@ namespace snapper
            throw AddConfigFailedException("cannot access template config");
        }
 
+       auto_ptr<Filesystem> filesystem;
+       try
+       {
+           filesystem.reset(Filesystem::create(fstype, subvolume));
+       }
+       catch (const InvalidConfigException& e)
+       {
+           throw AddConfigFailedException("invalid filesystem type");
+       }
+
        try
        {
            SysconfigFile sysconfig(SYSCONFIGFILE);
@@ -602,8 +610,17 @@ namespace snapper
            throw AddConfigFailedException("modifying config failed");
        }
 
-       auto_ptr<Filesystem> filesystem(Filesystem::create(fstype, subvolume));
        filesystem->addConfig();
     }
 
+
+    bool
+    Snapper::detectFstype(const string& subvolume, string& fstype)
+    {
+       // TODO
+
+       fstype = "btrfs";
+       return true;
+    }
+
 }
index 2f8eee00aa37b8752cf1632169df913c2a3d6cee..90a6f635c6bbbf3909cec872e310532596713822 100644 (file)
@@ -140,7 +140,9 @@ namespace snapper
 
        static list<ConfigInfo> getConfigs();
        static void addConfig(const string& config_name, const string& subvolume,
-                             const string& template_name);
+                             const string& fstype, const string& template_name);
+
+       static bool detectFstype(const string& subvolume, string& fstype);
 
        const Filesystem* getFilesystem() const { return filesystem; }
 
index 62c05de58ecd58698670d46eed5dd31086ec56ee..fa280d40ea6c82c2e4fe32766b3a12946e737b20 100644 (file)
@@ -98,6 +98,7 @@ void
 command_create_config()
 {
     const struct option options[] = {
+       { "fstype",             required_argument,      0,      'f' },
        { "template",           required_argument,      0,      't' },
        { 0, 0, 0, 0 }
     };
@@ -111,16 +112,26 @@ command_create_config()
 
     string subvolume = getopts.popArg();
 
+    string fstype = "";
     string template_name = "default";
 
     GetOpts::parsed_opts::const_iterator opt;
 
+    if ((opt = opts.find("fstype")) != opts.end())
+       fstype = opt->second;
+
     if ((opt = opts.find("template")) != opts.end())
        template_name = opt->second;
 
+    if (fstype.empty() && !Snapper::detectFstype(subvolume, fstype))
+    {
+       cerr << _("Detecting filesystem type failed.") << endl;
+       exit(EXIT_FAILURE);
+    }
+
     try
     {
-       Snapper::addConfig(config_name, subvolume, template_name);
+       Snapper::addConfig(config_name, subvolume, fstype, template_name);
     }
     catch (const AddConfigFailedException& e)
     {