Marc Olberding | 1e17db5 | 2025-08-27 12:25:28 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
Patrick Williams | 4a94352 | 2025-10-09 20:34:38 -0400 | [diff] [blame^] | 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
Marc Olberding | 1e17db5 | 2025-08-27 12:25:28 -0700 | [diff] [blame] | 3 | |
| 4 | #include "utilities.hpp" |
| 5 | |
| 6 | #include <chrono> |
| 7 | #include <filesystem> |
| 8 | #include <format> |
| 9 | #include <iostream> |
| 10 | #include <thread> |
| 11 | |
| 12 | using namespace std::chrono_literals; |
| 13 | |
| 14 | void sleep_milliseconds(std::chrono::milliseconds milliseconds) |
| 15 | { |
| 16 | std::cerr << std::format("Sleeping for {} milliseconds\n", |
| 17 | milliseconds.count()); |
| 18 | std::this_thread::sleep_for(milliseconds); |
| 19 | } |
| 20 | |
| 21 | void wait_for_path_to_exist(std::string_view path, |
| 22 | std::chrono::milliseconds timeout) |
| 23 | { |
Marc Olberding | 14ca31b | 2025-09-08 16:51:01 -0700 | [diff] [blame] | 24 | auto now = std::chrono::steady_clock::now(); |
| 25 | auto end = now + timeout; |
| 26 | std::cerr << std::format("waiting for {} to exist\n", path); |
Marc Olberding | 1e17db5 | 2025-08-27 12:25:28 -0700 | [diff] [blame] | 27 | while (true) |
| 28 | { |
| 29 | std::error_code ec; |
| 30 | bool exists = std::filesystem::exists(path, ec); |
| 31 | if (exists) |
| 32 | { |
| 33 | return; |
| 34 | } |
Marc Olberding | 14ca31b | 2025-09-08 16:51:01 -0700 | [diff] [blame] | 35 | std::this_thread::sleep_for(1ms); |
| 36 | |
| 37 | now = std::chrono::steady_clock::now(); |
| 38 | if (now > end) |
| 39 | { |
| 40 | break; |
| 41 | } |
Marc Olberding | 1e17db5 | 2025-08-27 12:25:28 -0700 | [diff] [blame] | 42 | } |
Marc Olberding | 14ca31b | 2025-09-08 16:51:01 -0700 | [diff] [blame] | 43 | std::cerr << std::format("Failed to wait for {} to exist\n", path); |
Marc Olberding | 1e17db5 | 2025-08-27 12:25:28 -0700 | [diff] [blame] | 44 | } |