From 05eeca49c9c25cae37c4851d2fe4fb31cc633c71 Mon Sep 17 00:00:00 2001 From: Nicholas O'Connor Date: Wed, 22 Mar 2017 18:12:12 -0700 Subject: [PATCH] now handles symlinks --- src/bottles.cpp | 58 +++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/src/bottles.cpp b/src/bottles.cpp index 50544aa..f251e13 100644 --- a/src/bottles.cpp +++ b/src/bottles.cpp @@ -25,31 +25,43 @@ vector cellar::bottles::list() { if (item.substr(0,5) == ".wine") { sstr_output << item; sstr_output << " "; + + string fullitem = homepath + "/" + item; + boost::filesystem::file_status fullitem_status = boost::filesystem::symlink_status(fullitem); + bool symlink = boost::filesystem::is_symlink(fullitem_status); - string jsonpath = homepath + "/" + item + "/cellar.json"; - if (boost::filesystem::exists(jsonpath)) { - try { - json config; - ifstream configstream(jsonpath); - stringstream sstr_config; - sstr_config << configstream.rdbuf(); - config = json::parse(sstr_config.str()); + if (symlink) { + sstr_output << "- symlink to "; + boost::filesystem::path realpath = boost::filesystem::canonical(fullitem); + sstr_output << realpath.string(); + result.push_back(sstr_output.str()); + sstr_output.str(""); + } else { + string jsonpath = fullitem + "/cellar.json"; + if (boost::filesystem::exists(jsonpath)) { + try { + json config; + ifstream configstream(jsonpath); + stringstream sstr_config; + 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(""); - } + 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(""); + } + } } }