| 324 | } |
| 325 | |
| 326 | std::vector<std::string> UMockdevDeviceManager::umockdevRemoveByFile(const std::string& definitions_path) |
| 327 | { |
| 328 | USBGUARD_LOG(Trace) << "definitions_path=" << definitions_path; |
| 329 | std::vector<std::string> device_paths; |
| 330 | const std::string umockdev_name = filenameFromPath(definitions_path, /*include_extension=*/true); |
| 331 | auto it = _umockdev_file_map.find(umockdev_name); |
| 332 | |
| 333 | while (it != _umockdev_file_map.end()) { |
| 334 | if (it->first != umockdev_name) { |
| 335 | break; |
| 336 | } |
| 337 | |
| 338 | std::shared_ptr<UMockdevDeviceDefinition> definition = it->second.lock(); |
| 339 | USBGUARD_LOG(Debug) << "device_paths <- " << definition->getSysfsPath(); |
| 340 | device_paths.push_back(definition->getSysfsPath()); |
| 341 | it = _umockdev_file_map.erase(it); |
| 342 | } |
| 343 | |
| 344 | const auto lambdaSysfsPathHierarchyCompare = [](const std::string& full_b, |
| 345 | const std::string& full_a) { |
| 346 | const std::size_t component_count_a = countPathComponents(full_a); |
| 347 | const std::size_t component_count_b = countPathComponents(full_b); |
| 348 | USBGUARD_LOG(Debug) << "c_c_a=" << component_count_a << " c_c_b=" << component_count_b; |
| 349 | |
| 350 | if (component_count_a < component_count_b) { |
| 351 | return true; |
| 352 | } |
| 353 | else if (component_count_a > component_count_b) { |
| 354 | return false; |
| 355 | } |
| 356 | |
| 357 | const std::string base_a = filenameFromPath(full_a, /*include_extension=*/true); |
| 358 | const std::string base_b = filenameFromPath(full_b, /*include_extension=*/true); |
| 359 | const bool a_has_usb_prefix = hasPrefix("usb", base_a); |
| 360 | const bool b_has_usb_prefix = hasPrefix("usb", base_b); |
| 361 | USBGUARD_LOG(Debug) << "a_p=" << a_has_usb_prefix << " b_p=" << b_has_usb_prefix; |
| 362 | |
| 363 | if (a_has_usb_prefix) { |
| 364 | if (!b_has_usb_prefix) { |
| 365 | return true; |
| 366 | } |
| 367 | } |
| 368 | else { |
| 369 | if (b_has_usb_prefix) { |
| 370 | return false; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | return base_a < base_b; |
| 375 | }; |
| 376 | std::sort(device_paths.begin(), device_paths.end(), lambdaSysfsPathHierarchyCompare); |
| 377 | return device_paths; |
| 378 | } |
| 379 | |
| 380 | std::vector<std::string> UMockdevDeviceManager::umockdevGetChildrenBySysfsPath(const std::string& sysfs_path) |
| 381 | { |
nothing calls this directly
no test coverage detected