From a6d9c341df126af9f265e66bcd559c1b8a14c20e Mon Sep 17 00:00:00 2001 From: Nicholas O'Connor Date: Thu, 23 Mar 2017 18:08:24 -0700 Subject: [PATCH] functional but naive activate command --- src/bottles/activate.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/bottles/activate.cpp b/src/bottles/activate.cpp index a446e73..ef5033f 100644 --- a/src/bottles/activate.cpp +++ b/src/bottles/activate.cpp @@ -1,12 +1,43 @@ +#include #include #include #include +#include +#include + #include "bottles.hpp" #include "internal/bottles.hpp" using namespace std; +using namespace boost::filesystem; void cellar::bottles::switch_active_bottle(int argc, vector argv) { - cout << argv[0] << endl; + if (argc == 1) { + cout << "forgot to specify a bottle to activate" << endl; + return; + } + + string homepath = getenv("HOME"); // /home/nick + string bottlepath = homepath + "/.wine"; // /home/nick/.wine + string targetpath = bottlepath + "." + argv[1]; // /home/nick/.wine.example + + file_status targetstatus = symlink_status(targetpath); + if (!exists(targetstatus)) { + cerr << "target " << targetpath << " does not exist" << endl; + return; + } + + file_status bottlestatus = symlink_status(bottlepath); + if (exists(bottlestatus)) { + bool bottlesymlink = is_symlink(bottlestatus); + if (!bottlesymlink) { + cerr << "refusing to clobber " << bottlepath << ": not a symlink" << endl; + return; + } + remove(bottlepath); + } + + // TODO: not blindly assume this will magically work + create_symlink(targetpath, bottlepath); }