Update Store HFT adapter to properly handle embedded devpaths
Devpaths may exist such as `/LOCALROOT:device:VALVE0` which have no slashes after the initial slash. Relying on splitting on `/` in this case will produce the wrong devpath of `/phys`. To correctly preserve the embedded suffix, we should find the first `:` in the devpath_part if it exists and remove the prefix before this from the devpath since this represents the local root. The remaining devpath can be joined with `/` to create the correct devpath to export.
After this cl, we have correct devpaths reported and for all sensors currently supported in metfuego.
#tlbmc
#tlbmc-hft
PiperOrigin-RevId: 820768010
Change-Id: I58efc56cf6ef723c4e7efe82a0f231bda475068d
diff --git a/tlbmc/store/store_hft_adapter.cc b/tlbmc/store/store_hft_adapter.cc
index 681fc6f..5dd02a1 100644
--- a/tlbmc/store/store_hft_adapter.cc
+++ b/tlbmc/store/store_hft_adapter.cc
@@ -1,5 +1,6 @@
#include "tlbmc/store/store_hft_adapter.h"
+#include <cstddef>
#include <memory>
#include <string>
#include <vector>
@@ -9,6 +10,7 @@
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/match.h"
+#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
@@ -80,7 +82,13 @@
return absl::InternalError(
absl::Substitute("Invalid devpath: $0", devpath));
}
- devpath_parts[1] = "phys";
+ size_t device_index = devpath_parts[1].find_first_of(':');
+ if (device_index != std::string::npos) {
+ devpath_parts[1] =
+ absl::StrCat("phys", devpath_parts[1].substr(device_index));
+ } else {
+ devpath_parts[1] = "phys";
+ }
sensor_identifier_from_readings->set_devpath(
absl::StrJoin(devpath_parts, "/"));
} else {