init: Move the stripping of "/devices" and "/devices/platform/" to a helper

A future change will want the same stripping when looking for USB boot
devices. Move the stripping down to the helper.

This change is intended to be a no-op and just a reorganization.

Bug: 316324155
Test: See boot devices still found
Change-Id: I025d9d68fedf652055454cbd93e15f480b6056dd
This commit is contained in:
Douglas Anderson 2024-10-22 14:13:19 -07:00
parent 6519e6d67f
commit 3de05fcff6

View file

@ -193,14 +193,6 @@ BlockDeviceInfo DeviceHandler::GetBlockDeviceInfo(const std::string& uevent_path
BlockDeviceInfo info;
if (FindPlatformDevice(uevent_path, &info.str)) {
// Skip /devices/platform or /devices/ if present
static constexpr std::string_view devices_platform_prefix = "/devices/platform/";
static constexpr std::string_view devices_prefix = "/devices/";
std::string_view str = info.str;
if (ConsumePrefix(&str, devices_platform_prefix) || ConsumePrefix(&str, devices_prefix)) {
info.str = str;
}
info.type = "platform";
} else if (FindPciDevicePrefix(uevent_path, &info.str)) {
info.type = "pci";
@ -265,7 +257,17 @@ bool DeviceHandler::FindSubsystemDevice(std::string path, std::string* device_pa
subsystem_paths.find(subsystem_link_path) != subsystem_paths.end()) {
// We need to remove the mount point that we added above before returning.
directory.erase(0, sysfs_mount_point_.size());
*device_path = directory;
// Skip /devices/platform or /devices/ if present
static constexpr std::string_view devices_platform_prefix = "/devices/platform/";
static constexpr std::string_view devices_prefix = "/devices/";
std::string_view sv = directory;
if (!ConsumePrefix(&sv, devices_platform_prefix)) {
ConsumePrefix(&sv, devices_prefix);
}
*device_path = sv;
return true;
}