now handles symlinks

This commit is contained in:
Nicholas O'Connor 2017-03-22 18:12:12 -07:00
parent f69095d7ab
commit 05eeca49c9

View File

@ -26,30 +26,42 @@ vector<string> cellar::bottles::list() {
sstr_output << item; sstr_output << item;
sstr_output << " "; sstr_output << " ";
string jsonpath = homepath + "/" + item + "/cellar.json"; string fullitem = homepath + "/" + item;
if (boost::filesystem::exists(jsonpath)) { boost::filesystem::file_status fullitem_status = boost::filesystem::symlink_status(fullitem);
try { bool symlink = boost::filesystem::is_symlink(fullitem_status);
json config;
ifstream configstream(jsonpath);
stringstream sstr_config;
sstr_config << configstream.rdbuf();
config = json::parse(sstr_config.str());
sstr_output << "- " << config["name"]; if (symlink) {
result.push_back(sstr_output.str()); sstr_output << "- symlink to ";
sstr_output.str(""); // clear it for the next item boost::filesystem::path realpath = boost::filesystem::canonical(fullitem);
} sstr_output << realpath.string();
catch (const exception &exc) { result.push_back(sstr_output.str());
sstr_output << "- bogus cellar.json file"; sstr_output.str("");
result.push_back(sstr_output.str()); } else {
sstr_output.str(""); string jsonpath = fullitem + "/cellar.json";
} if (boost::filesystem::exists(jsonpath)) {
} try {
else { json config;
sstr_output << "- anonymous wine bottle"; ifstream configstream(jsonpath);
result.push_back(sstr_output.str()); stringstream sstr_config;
sstr_output.str(""); sstr_config << configstream.rdbuf();
} config = json::parse(sstr_config.str());
sstr_output << "- " << config["name"];
result.push_back(sstr_output.str());
sstr_output.str(""); // clear it for the next item
}
catch (const exception &exc) {
sstr_output << "- bogus cellar.json file";
result.push_back(sstr_output.str());
sstr_output.str("");
}
}
else {
sstr_output << "- anonymous wine bottle";
result.push_back(sstr_output.str());
sstr_output.str("");
}
}
} }
} }