pressing supports dry runs

This commit is contained in:
Nicholas O'Connor 2017-07-05 16:49:32 -07:00
parent b979bb7a0a
commit ffb952fae6

View File

@ -7,6 +7,7 @@
#include "json.hpp" #include "json.hpp"
#include "bottles.hpp" #include "bottles.hpp"
#include "cellar.hpp"
#include "internal/bottles.hpp" #include "internal/bottles.hpp"
#include "launch.hpp" #include "launch.hpp"
#include "internal/launch.hpp" #include "internal/launch.hpp"
@ -24,31 +25,43 @@ void cellar::bottles::press(string exec, vector<string> args, bool noexec) {
string homedir = getenv("HOME"); string homedir = getenv("HOME");
string datadir = homedir + "/.local/share/cellar"; string datadir = homedir + "/.local/share/cellar";
string presseddir = datadir + "/pressed"; string presseddir = datadir + "/pressed";
if (!boost::filesystem::exists(datadir)) { boost::filesystem::create_directory(datadir); }
if (!boost::filesystem::exists(presseddir)) { boost::filesystem::create_directory(presseddir); } output::statement("making sure " + presseddir + " exists", true);
if (!dryrun) {
if (!boost::filesystem::exists(datadir)) { boost::filesystem::create_directory(datadir); }
if (!boost::filesystem::exists(presseddir)) { boost::filesystem::create_directory(presseddir); }
}
string filename = boost::filesystem::path(exec).filename().native(); string filename = boost::filesystem::path(exec).filename().native();
auto pressedpath = boost::filesystem::path(presseddir); auto pressedpath = boost::filesystem::path(presseddir);
string pressedfile = (pressedpath / filename).native(); string pressedfile = (pressedpath / filename).native();
if (boost::filesystem::exists(pressedfile)) { if (boost::filesystem::exists(pressedfile)) {
output::warning("clobbering existing version of " + filename); output::warning("clobbering existing version of " + filename);
boost::filesystem::remove(pressedfile); if (!dryrun) { boost::filesystem::remove(pressedfile); }
} }
boost::filesystem::copy(exec, pressedfile); output::statement("copying " + exec + " to " + pressedfile);
if (!dryrun) { boost::filesystem::copy(exec, pressedfile); }
vector<string> argv; vector<string> argv;
argv.push_back("wine"); argv.push_back("wine");
argv.push_back(pressedfile); argv.push_back(pressedfile);
if (!noexec) { launch::popen(argv); } if (!noexec) {
output::statement("launching " + pressedfile, true);
if (!dryrun) { launch::popen(argv); }
}
if (active_bottle.config.find("pressed") == active_bottle.config.end()) { if (active_bottle.config.find("pressed") == active_bottle.config.end()) {
json pressed; json pressed;
active_bottle.config["pressed"] = pressed; output::statement("no pressed object in json, creating", true);
if (!dryrun) { active_bottle.config["pressed"] = pressed; }
} }
active_bottle.config["pressed"].emplace(filename, args); output::statement("recording pressed installer", true);
active_bottle.save_config(); if (!dryrun) {
active_bottle.config["pressed"].emplace(filename, args);
active_bottle.save_config();
}
} }
void cellar::bottles::press_command(int argc, vector<string> argv) { void cellar::bottles::press_command(int argc, vector<string> argv) {