Marc Olberding | 1e17db5 | 2025-08-27 12:25:28 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: 2025 NVIDIA |
| 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 | { |
| 24 | while (true) |
| 25 | { |
| 26 | std::error_code ec; |
| 27 | bool exists = std::filesystem::exists(path, ec); |
| 28 | if (exists) |
| 29 | { |
| 30 | return; |
| 31 | } |
| 32 | sleep_milliseconds(1ms); |
| 33 | timeout -= 1ms; |
| 34 | } |
| 35 | std::cerr << std::format("Failed to wait for {} to exist", path); |
| 36 | } |