From b050c1f53cd633d0e1414c3c0f0c247de2628b1c Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Mon, 4 Jul 2016 16:47:48 +0200 Subject: [PATCH] Add simple reset command to reset container state --- src/CMakeLists.txt | 1 + src/anbox/cmds/reset.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/anbox/cmds/reset.h | 36 ++++++++++++++++++++++++++++++++++++ src/anbox/daemon.cpp | 6 ++++-- 4 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 src/anbox/cmds/reset.cpp create mode 100644 src/anbox/cmds/reset.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 289dd5d..44357bc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -104,6 +104,7 @@ set(SOURCES anbox/cmds/shell.cpp anbox/cmds/install_app.cpp anbox/cmds/launch_app.cpp + anbox/cmds/reset.cpp anbox/do_not_copy_or_move.h anbox/optional.h diff --git a/src/anbox/cmds/reset.cpp b/src/anbox/cmds/reset.cpp new file mode 100644 index 0000000..1583f8e --- /dev/null +++ b/src/anbox/cmds/reset.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2016 Simon Fels + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, 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 warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, 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, see . + * + */ + +#include + +#include "anbox/config.h" +#include "anbox/cmds/reset.h" + +namespace fs = boost::filesystem; + +anbox::cmds::Reset::Reset() + : CommandWithFlagsAndAction{cli::Name{"reset"}, cli::Usage{"reset"}, cli::Description{"Reset the container to its default settings"}} +{ + action([this](const cli::Command::Context &) { + // FIXME(morphis): check if container is currently running and if stop here. + + if (!fs::is_directory(config::data_path())) + return EXIT_SUCCESS; + + // FIXME(morphis): This currently requires us to run as root as otherwise we can't + // remove some of the files stored there even if they are created from a user namespace!? + fs::remove_all(config::data_path()); + + return EXIT_SUCCESS; + }); +} diff --git a/src/anbox/cmds/reset.h b/src/anbox/cmds/reset.h new file mode 100644 index 0000000..430aa63 --- /dev/null +++ b/src/anbox/cmds/reset.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2016 Simon Fels + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, 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 warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, 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, see . + * + */ + +#ifndef ANBOX_CMDS_RESET_H_ +#define ANBOX_CMDS_RESET_H_ + +#include +#include +#include + +#include "anbox/cli.h" + +namespace anbox { +namespace cmds { +class Reset : public cli::CommandWithFlagsAndAction { +public: + Reset(); +}; +} // namespace cmds +} // namespace anbox + +#endif diff --git a/src/anbox/daemon.cpp b/src/anbox/daemon.cpp index da7735e..f43e0a2 100644 --- a/src/anbox/daemon.cpp +++ b/src/anbox/daemon.cpp @@ -27,6 +27,7 @@ #include "anbox/cmds/shell.h" #include "anbox/cmds/install_app.h" #include "anbox/cmds/launch_app.h" +#include "anbox/cmds/reset.h" #include @@ -40,7 +41,8 @@ Daemon::Daemon() : .command(std::make_shared()) .command(std::make_shared()) .command(std::make_shared()) - .command(std::make_shared()); + .command(std::make_shared()) + .command(std::make_shared()); } int Daemon::Run(const std::vector &arguments) @@ -64,7 +66,7 @@ void Daemon::ensure_data_path() { for (const auto &path: paths) { if (!fs::is_directory(fs::path(path))) - fs::create_directories(fs::path(config::host_share_path())); + fs::create_directories(fs::path(path)); } } } // namespace anbox