From: Arvin Schnell Date: Thu, 10 Feb 2011 09:27:25 +0000 (+0100) Subject: - allow to change description of snapshots X-Git-Tag: v0.1.3~496 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=8105f1e73dce83ca93c66f7a6277f4dc2d975ee2;p=thirdparty%2Fsnapper.git - allow to change description of snapshots --- diff --git a/snapper/Snapshot.cc b/snapper/Snapshot.cc index dbff0cd8..62d05506 100644 --- a/snapper/Snapshot.cc +++ b/snapper/Snapshot.cc @@ -75,6 +75,14 @@ namespace snapper } + void + Snapshot::setDescription(const string& desc) + { + description = desc; + writeInfo(); + } + + void Snapshots::read() { @@ -246,7 +254,7 @@ namespace snapper setChildValue(node, "date", datetime(date, true, true)); - if ((type == SINGLE || type == PRE) && !description.empty()) + if (!description.empty()) setChildValue(node, "description", description); if (type == POST) diff --git a/snapper/Snapshot.h b/snapper/Snapshot.h index 599efca3..a0e8208b 100644 --- a/snapper/Snapshot.h +++ b/snapper/Snapshot.h @@ -54,6 +54,7 @@ namespace snapper time_t getDate() const { return date; } + void setDescription(const string& description); string getDescription() const { return description; } unsigned int getPreNum() const { return pre_num; } @@ -71,13 +72,14 @@ namespace snapper time_t date; - string description; // empty for type=POST + string description; // likely empty for type=POST unsigned int pre_num; // valid only for type=POST bool writeInfo() const; bool createFilesystemSnapshot() const; bool deleteFilesystemSnapshot() const; + }; diff --git a/tools/snapper.cc b/tools/snapper.cc index 324e9fab..2ccc129d 100644 --- a/tools/snapper.cc +++ b/tools/snapper.cc @@ -170,6 +170,42 @@ command_create() } +void +help_modify() +{ + cout << _(" Modify snapshot:") << endl + << _("\tsnapper modify ") << endl + << endl + << _(" Options for 'modify' command:") << endl + << _("\t--description, -d \tDescription for snapshot.") << endl + << endl; +} + + +void +command_modify() +{ + const struct option options[] = { + { "description", required_argument, 0, 'd' }, + { 0, 0, 0, 0 } + }; + + GetOpts::parsed_opts opts = getopts.parse("modify", options); + if (getopts.numArgs() != 1) + { + cerr << _("Command 'modify' need one argument.") << endl; + exit(EXIT_FAILURE); + } + + Snapshots::iterator snapshot = readNum(getopts.popArg()); + + GetOpts::parsed_opts::const_iterator it; + + if ((it = opts.find("description")) != opts.end()) + snapshot->setDescription(it->second); +} + + void help_delete() { @@ -345,6 +381,7 @@ command_help() help_list(); help_create(); + help_modify(); help_delete(); help_diff(); help_rollback(); @@ -369,6 +406,7 @@ main(int argc, char** argv) cmds["list"] = command_list; cmds["create"] = command_create; + cmds["modify"] = command_modify; cmds["delete"] = command_delete; cmds["diff"] = command_diff; cmds["rollback"] = command_rollback;