From: Arvin Schnell Date: Tue, 2 Aug 2011 12:20:03 +0000 (+0200) Subject: - added option to set fstype X-Git-Tag: v0.1.3~324 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=aff368fd967b4533eb7fb00026752a337d3135ea;p=thirdparty%2Fsnapper.git - added option to set fstype --- diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index c731fcc4..ee5b3883 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -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; + 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::create(fstype, subvolume)); filesystem->addConfig(); } + + bool + Snapper::detectFstype(const string& subvolume, string& fstype) + { + // TODO + + fstype = "btrfs"; + return true; + } + } diff --git a/snapper/Snapper.h b/snapper/Snapper.h index 2f8eee00..90a6f635 100644 --- a/snapper/Snapper.h +++ b/snapper/Snapper.h @@ -140,7 +140,9 @@ namespace snapper static list 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; } diff --git a/tools/snapper.cc b/tools/snapper.cc index 62c05de5..fa280d40 100644 --- a/tools/snapper.cc +++ b/tools/snapper.cc @@ -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) {