From: Arvin Schnell Date: Fri, 28 Aug 2020 10:45:03 +0000 (+0200) Subject: - move commands to separate files X-Git-Tag: v0.8.14~32^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a50e13cb6f717456438dcc383dc48ce047a70d95;p=thirdparty%2Fsnapper.git - move commands to separate files --- diff --git a/client/Makefile.am b/client/Makefile.am index ae4a8e65..8843a837 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -20,11 +20,32 @@ bin_PROGRAMS = snapper snapper_SOURCES = \ snapper.cc \ + cmd.h \ + cmd-list-configs.cc \ + cmd-create-config.cc \ + cmd-delete-config.cc \ + cmd-get-config.cc \ + cmd-set-config.cc \ + cmd-list.cc \ + cmd-create.cc \ + cmd-modify.cc \ + cmd-delete.cc \ + cmd-mount.cc \ + cmd-umount.cc \ + cmd-status.cc \ + cmd-diff.cc \ + cmd-xadiff.cc \ + cmd-undochange.cc \ + cmd-rollback.cc \ + cmd-setup-quota.cc \ + cmd-cleanup.cc \ + cmd-debug.cc \ cleanup.cc cleanup.h \ proxy.cc proxy.h \ proxy-dbus.cc proxy-dbus.h \ proxy-lib.cc proxy-lib.h \ misc.cc misc.h \ + MyFiles.cc MyFiles.h \ Options.cc Options.h \ GlobalOptions.cc GlobalOptions.h \ Command.cc Command.h diff --git a/client/MyFiles.cc b/client/MyFiles.cc new file mode 100644 index 00000000..2a19a8ae --- /dev/null +++ b/client/MyFiles.cc @@ -0,0 +1,100 @@ +/* + * Copyright (c) [2011-2015] Novell, Inc. + * Copyright (c) [2016-2020] SUSE LLC + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + + +#include + +#include "proxy.h" +#include "utils/text.h" +#include "GlobalOptions.h" + +#include +#include + +#include "MyFiles.h" + + +namespace snapper +{ + + void + MyFiles::bulk_process(FILE* file, GetOpts& get_opts, std::function callback) + { + if (file) + { + AsciiFileReader asciifile(file); + + string line; + while (asciifile.getline(line)) + { + if (line.empty()) + continue; + + string name = line; + + // strip optional status + if (name[0] != '/') + { + string::size_type pos = name.find(" "); + if (pos == string::npos) + continue; + + name.erase(0, pos + 1); + } + + Files::iterator it = findAbsolutePath(name); + if (it == end()) + { + cerr << sformat(_("File '%s' not found."), name.c_str()) << endl; + exit(EXIT_FAILURE); + } + + callback(*it); + } + } + else + { + if (get_opts.num_args() == 0) + { + for (Files::iterator it = begin(); it != end(); ++it) + callback(*it); + } + else + { + while (get_opts.num_args() > 0) + { + string name = get_opts.pop_arg(); + + Files::iterator it = findAbsolutePath(name); + if (it == end()) + { + cerr << sformat(_("File '%s' not found."), name.c_str()) << endl; + exit(EXIT_FAILURE); + } + + callback(*it); + } + } + } + } + +} diff --git a/client/MyFiles.h b/client/MyFiles.h new file mode 100644 index 00000000..b3dfcd6a --- /dev/null +++ b/client/MyFiles.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) [2011-2015] Novell, Inc. + * Copyright (c) [2016-2020] SUSE LLC + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + + +#include + +#include + +#include "utils/GetOpts.h" + + +namespace snapper +{ + + struct MyFiles : public Files + { + + MyFiles(const Files& files) : Files(files) {} + + void bulk_process(FILE* file, GetOpts& get_opts, std::function callback); + + }; + +} diff --git a/client/cmd-cleanup.cc b/client/cmd-cleanup.cc new file mode 100644 index 00000000..62bf065b --- /dev/null +++ b/client/cmd-cleanup.cc @@ -0,0 +1,80 @@ +/* + * Copyright (c) [2011-2015] Novell, Inc. + * Copyright (c) [2016-2020] SUSE LLC + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + + +#include + +#include + +#include "utils/text.h" +#include "GlobalOptions.h" +#include "proxy.h" +#include "cleanup.h" + + +namespace snapper +{ + + using namespace std; + + + void + help_cleanup() + { + cout << _(" Cleanup snapshots:") << '\n' + << _("\tsnapper cleanup ") << '\n' + << endl; + } + + + void + command_cleanup(GlobalOptions& global_options, GetOpts& get_opts, ProxySnappers* snappers, ProxySnapper* snapper) + { + ParsedOpts opts = get_opts.parse("cleanup", GetOpts::no_options); + if (get_opts.num_args() != 1) + { + cerr << _("Command 'cleanup' needs one arguments.") << endl; + exit(EXIT_FAILURE); + } + + string cleanup = get_opts.pop_arg(); + + if (cleanup == "number") + { + do_cleanup_number(snapper, global_options.verbose()); + } + else if (cleanup == "timeline") + { + do_cleanup_timeline(snapper, global_options.verbose()); + } + else if (cleanup == "empty-pre-post") + { + do_cleanup_empty_pre_post(snapper, global_options.verbose()); + } + else + { + cerr << sformat(_("Unknown cleanup algorithm '%s'."), cleanup.c_str()) << endl; + exit(EXIT_FAILURE); + } + } + +} diff --git a/client/cmd-create-config.cc b/client/cmd-create-config.cc new file mode 100644 index 00000000..b7e426b9 --- /dev/null +++ b/client/cmd-create-config.cc @@ -0,0 +1,94 @@ +/* + * Copyright (c) [2011-2015] Novell, Inc. + * Copyright (c) [2016-2020] SUSE LLC + * + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, contact Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, you may + * find current contact information at www.novell.com. + */ + + +#include + +#include + +#include "utils/text.h" +#include "GlobalOptions.h" +#include "proxy.h" + + +namespace snapper +{ + + using namespace std; + + + void + help_create_config() + { + cout << _(" Create config:") << '\n' + << _("\tsnapper create-config ") << '\n' + << '\n' + << _(" Options for 'create-config' command:") << '\n' + << _("\t--fstype, -f \t\tManually set filesystem type.") << '\n' + << _("\t--template, -t \t\tName of config template to use.") << '\n' + << endl; + } + + + void + command_create_config(GlobalOptions& global_options, GetOpts& get_opts, ProxySnappers* snappers, ProxySnapper*) + { + const vector