From d0e1330fcf0619e1bf3429131d887395aaabaff0 Mon Sep 17 00:00:00 2001 From: Priyank Warkhede Date: Wed, 14 Aug 2024 13:56:17 -0700 Subject: [PATCH] Fix show fsdb subscribers to handle patch subs Summary: For patch subscribers, in OperSubscriberInfo optional path and extendedPaths would not present. Add check to ensure that "fboss2 show fsdb subscribers" doesn't crash in this case. Reviewed By: wilsonwinhi Differential Revision: D60996692 fbshipit-source-id: b521e4a360e865918d9d8fa63b88d90c376f771e --- fboss/cli/fboss2/utils/CmdUtils.cpp | 33 +++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/fboss/cli/fboss2/utils/CmdUtils.cpp b/fboss/cli/fboss2/utils/CmdUtils.cpp index fb7478c63cd3d..acb44c586e42b 100644 --- a/fboss/cli/fboss2/utils/CmdUtils.cpp +++ b/fboss/cli/fboss2/utils/CmdUtils.cpp @@ -242,7 +242,10 @@ std::optional getMyHostname(const std::string& hostname) { } std::string escapeDoubleQuotes(const std::string& cmd) { - return std::regex_replace(cmd, std::regex("\""), "\\\""); + std::string cmdCopy = cmd; + const re2::RE2 doubleQuotes("\""); + re2::RE2::Replace(&cmdCopy, doubleQuotes, "\\\""); + return cmdCopy; } std::string getCmdToRun(const std::string& hostname, const std::string& cmd) { @@ -293,18 +296,26 @@ std::string getSubscriptionPathStr(const fsdb::OperSubscriberInfo& subscriber) { return folly::join("/", subscriber.get_path()->get_raw()); } std::vector extPaths; - for (const auto& extPath : *subscriber.get_extendedPaths()) { - std::vector pathElements; - for (const auto& pathElm : *extPath.path()) { - if (pathElm.any_ref().has_value()) { - pathElements.push_back("*"); - } else if (pathElm.regex_ref().has_value()) { - pathElements.push_back(*pathElm.regex_ref()); - } else { - pathElements.push_back(*pathElm.raw_ref()); + if (auto subExtPaths = subscriber.get_extendedPaths()) { + for (const auto& extPath : *subExtPaths) { + std::vector pathElements; + for (const auto& pathElm : *extPath.path()) { + if (pathElm.any_ref().has_value()) { + pathElements.push_back("*"); + } else if (pathElm.regex_ref().has_value()) { + pathElements.push_back(*pathElm.regex_ref()); + } else { + pathElements.push_back(*pathElm.raw_ref()); + } } + extPaths.push_back(folly::join("/", pathElements)); + } + } + auto paths = subscriber.get_paths(); + if (paths) { + for (const auto& path : *paths) { + extPaths.push_back(folly::join("/", path.second.get_path())); } - extPaths.push_back(folly::join("/", pathElements)); } return folly::join(";", extPaths); }