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)
{
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);
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;
+ }
+
}
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; }
command_create_config()
{
const struct option options[] = {
+ { "fstype", required_argument, 0, 'f' },
{ "template", required_argument, 0, 't' },
{ 0, 0, 0, 0 }
};
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)
{