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); }