From 4a148b7bf6ecd5eb3981288bb78a47c9fe4319d4 Mon Sep 17 00:00:00 2001 From: Nicholas O'Connor Date: Tue, 11 Jul 2017 14:23:25 -0700 Subject: [PATCH] cork and uncork respect dryrun --- src/bottles/cork.cpp | 93 +++++++++++++++++++++++++++++++------------- 1 file changed, 65 insertions(+), 28 deletions(-) diff --git a/src/bottles/cork.cpp b/src/bottles/cork.cpp index 9807cf7..86d688d 100644 --- a/src/bottles/cork.cpp +++ b/src/bottles/cork.cpp @@ -1,5 +1,7 @@ #include +#include #include +#include #include #include @@ -9,6 +11,7 @@ #include "bottles.hpp" #include "internal/bottles.hpp" +#include "cellar.hpp" #include "launch.hpp" #include "internal/launch.hpp" #include "fs.hpp" @@ -40,9 +43,13 @@ void cellar::bottles::cork(string bottlearg, bool remove) { return; } - boost::filesystem::copy(bottlepath + "/cellar.json", datadir + "/corked/" + bottlearg + ".json"); + output::statement("copying " + bottlepath + "/cellar.json to cork directory", true); + if (!cellar::dryrun) { boost::filesystem::copy(bottlepath + "/cellar.json", corkpath); } - if (remove) { fs::recursive_remove(bottlepath); } + if (remove) { + output::statement("removing bottle " + bottlearg + " at " + bottlepath, true); + if (!cellar::dryrun) { fs::recursive_remove(bottlepath); } + } } void cellar::bottles::cork_command(int argc, vector argv) { @@ -53,7 +60,8 @@ void cellar::bottles::cork_command(int argc, vector argv) { void cellar::bottles::uncork(string bottlearg) { string homedir = getenv("HOME"); string datadir = homedir + "/.local/share/cellar"; - if (!boost::filesystem::exists(datadir + "/corked/" + bottlearg + ".json")) { + string corkjsonpath = datadir + "/corked/" + bottlearg + ".json"; + if (!boost::filesystem::exists(corkjsonpath)) { output::error("no bottle named " + bottlearg + " to uncork"); return; } @@ -65,34 +73,63 @@ void cellar::bottles::uncork(string bottlearg) { } output::statement("creating wine prefix at " + bottlepath, true); - setenv("WINEPREFIX", bottlepath.c_str(), 1); - vector createargs = {"cellar create", bottlearg}; - create_bottle(2, createargs); - boost::filesystem::copy(datadir + "/corked/" + bottlearg + ".json", bottlepath + "/cellar.json"); + if (!cellar::dryrun) { + setenv("WINEPREFIX", bottlepath.c_str(), 1); + vector createargs = {"cellar create", bottlearg}; + create_bottle(2, createargs); + boost::filesystem::copy(corkjsonpath, bottlepath + "/cellar.json"); - active_bottle = Bottle(bottlepath); + active_bottle = Bottle(bottlepath); - if (active_bottle.config.find("winetricks") != active_bottle.config.end()) { - vector winetrickery = active_bottle.config.at("winetricks"); - output::statement("running winetricks with args: " + boost::algorithm::join(winetrickery, " ")); - launch::winetricks(winetrickery.size(), winetrickery); - } - - if (active_bottle.config.find("pressed") != active_bottle.config.end()) { - auto presseddir = boost::filesystem::path(datadir + "/pressed"); - auto pressed = active_bottle.config.at("pressed"); - for (auto pressed_iter = pressed.begin(); pressed_iter != pressed.end(); pressed_iter++) { - string exec = pressed_iter.key(); - vector args = pressed_iter.value(); - - output::statement("running pressed installer " + exec + " with arguments: " + boost::algorithm::join(args, " "), true); - vector subargv; - subargv.push_back("wine"); - subargv.push_back((presseddir / exec).native()); - for (string arg : args) { subargv.push_back(arg); } - launch::popen(subargv); + if (active_bottle.config.find("winetricks") != active_bottle.config.end()) { + vector winetrickery = active_bottle.config.at("winetricks"); + output::statement("running winetricks with args: " + boost::algorithm::join(winetrickery, " ")); + launch::winetricks(winetrickery.size(), winetrickery); } - } + + if (active_bottle.config.find("pressed") != active_bottle.config.end()) { + auto presseddir = boost::filesystem::path(datadir + "/pressed"); + auto pressed = active_bottle.config.at("pressed"); + for (auto pressed_iter = pressed.begin(); pressed_iter != pressed.end(); pressed_iter++) { + string exec = pressed_iter.key(); + vector args = pressed_iter.value(); + + output::statement("running pressed installer " + exec + " with arguments: " + boost::algorithm::join(args, " "), true); + vector subargv; + subargv.push_back("wine"); + subargv.push_back((presseddir / exec).native()); + for (string arg : args) { subargv.push_back(arg); } + launch::popen(subargv); + } + } + } else { + // load config to see what would have been done + json config; + ifstream configstream(corkjsonpath); + stringstream sstr; + sstr << configstream.rdbuf(); + config = json::parse(sstr.str()); + + if (config.find("winetricks") != config.end()) { + vector winetrickery = config.at("winetricks"); + output::statement("running winetricks with args: " + boost::algorithm::join(winetrickery, " ")); + } + + if (config.find("pressed") != config.end()) { + auto presseddir = boost::filesystem::path(datadir + "/pressed"); + auto pressed = active_bottle.config.at("pressed"); + for (auto pressed_iter = pressed.begin(); pressed_iter != pressed.end(); pressed_iter++) { + string exec = pressed_iter.key(); + vector args = pressed_iter.value(); + + output::statement("running pressed installer " + exec + " with arguments: " + boost::algorithm::join(args, " "), true); + vector subargv; + subargv.push_back("wine"); + subargv.push_back((presseddir / exec).native()); + for (string arg : args) { subargv.push_back(arg); } + } + } + } } void cellar::bottles::uncork_command(int argc, vector argv) { uncork(argv[1]); }