Add simple reset command to reset container state
This commit is contained in:
parent
f59a768b5f
commit
b050c1f53c
4 changed files with 81 additions and 2 deletions
|
|
@ -104,6 +104,7 @@ set(SOURCES
|
||||||
anbox/cmds/shell.cpp
|
anbox/cmds/shell.cpp
|
||||||
anbox/cmds/install_app.cpp
|
anbox/cmds/install_app.cpp
|
||||||
anbox/cmds/launch_app.cpp
|
anbox/cmds/launch_app.cpp
|
||||||
|
anbox/cmds/reset.cpp
|
||||||
|
|
||||||
anbox/do_not_copy_or_move.h
|
anbox/do_not_copy_or_move.h
|
||||||
anbox/optional.h
|
anbox/optional.h
|
||||||
|
|
|
||||||
40
src/anbox/cmds/reset.cpp
Normal file
40
src/anbox/cmds/reset.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
});
|
||||||
|
}
|
||||||
36
src/anbox/cmds/reset.h
Normal file
36
src/anbox/cmds/reset.h
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
|
||||||
|
*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ANBOX_CMDS_RESET_H_
|
||||||
|
#define ANBOX_CMDS_RESET_H_
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "anbox/cli.h"
|
||||||
|
|
||||||
|
namespace anbox {
|
||||||
|
namespace cmds {
|
||||||
|
class Reset : public cli::CommandWithFlagsAndAction {
|
||||||
|
public:
|
||||||
|
Reset();
|
||||||
|
};
|
||||||
|
} // namespace cmds
|
||||||
|
} // namespace anbox
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -27,6 +27,7 @@
|
||||||
#include "anbox/cmds/shell.h"
|
#include "anbox/cmds/shell.h"
|
||||||
#include "anbox/cmds/install_app.h"
|
#include "anbox/cmds/install_app.h"
|
||||||
#include "anbox/cmds/launch_app.h"
|
#include "anbox/cmds/launch_app.h"
|
||||||
|
#include "anbox/cmds/reset.h"
|
||||||
|
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
|
||||||
|
|
@ -40,7 +41,8 @@ Daemon::Daemon() :
|
||||||
.command(std::make_shared<cmds::Run>())
|
.command(std::make_shared<cmds::Run>())
|
||||||
.command(std::make_shared<cmds::Shell>())
|
.command(std::make_shared<cmds::Shell>())
|
||||||
.command(std::make_shared<cmds::InstallApp>())
|
.command(std::make_shared<cmds::InstallApp>())
|
||||||
.command(std::make_shared<cmds::LaunchApp>());
|
.command(std::make_shared<cmds::LaunchApp>())
|
||||||
|
.command(std::make_shared<cmds::Reset>());
|
||||||
}
|
}
|
||||||
|
|
||||||
int Daemon::Run(const std::vector<std::string> &arguments)
|
int Daemon::Run(const std::vector<std::string> &arguments)
|
||||||
|
|
@ -64,7 +66,7 @@ void Daemon::ensure_data_path() {
|
||||||
|
|
||||||
for (const auto &path: paths) {
|
for (const auto &path: paths) {
|
||||||
if (!fs::is_directory(fs::path(path)))
|
if (!fs::is_directory(fs::path(path)))
|
||||||
fs::create_directories(fs::path(config::host_share_path()));
|
fs::create_directories(fs::path(path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace anbox
|
} // namespace anbox
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue