cellar/src/bottles/activate.cpp

44 lines
1.3 KiB
C++
Raw Normal View History

2017-03-23 18:08:24 -07:00
#include <cstdlib>
2017-03-23 15:03:02 -07:00
#include <iostream>
#include <string>
#include <vector>
2017-03-23 15:03:02 -07:00
2017-03-23 18:08:24 -07:00
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
2017-03-23 15:03:02 -07:00
#include "bottles.hpp"
#include "internal/bottles.hpp"
using namespace std;
2017-03-23 18:08:24 -07:00
using namespace boost::filesystem;
2017-03-23 15:03:02 -07:00
void cellar::bottles::switch_active_bottle(int argc, vector<string> argv) {
2017-03-23 18:08:24 -07:00
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);
2017-03-23 15:03:02 -07:00
}