-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.cpp
More file actions
44 lines (38 loc) · 1.12 KB
/
utilities.cpp
File metadata and controls
44 lines (38 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright OpenBMC Authors
#include "utilities.hpp"
#include <chrono>
#include <filesystem>
#include <format>
#include <iostream>
#include <thread>
using namespace std::chrono_literals;
void sleep_milliseconds(std::chrono::milliseconds milliseconds)
{
std::cerr << std::format("Sleeping for {} milliseconds\n",
milliseconds.count());
std::this_thread::sleep_for(milliseconds);
}
void wait_for_path_to_exist(std::string_view path,
std::chrono::milliseconds timeout)
{
auto now = std::chrono::steady_clock::now();
auto end = now + timeout;
std::cerr << std::format("waiting for {} to exist\n", path);
while (true)
{
std::error_code ec;
bool exists = std::filesystem::exists(path, ec);
if (exists)
{
return;
}
std::this_thread::sleep_for(1ms);
now = std::chrono::steady_clock::now();
if (now > end)
{
break;
}
}
std::cerr << std::format("Failed to wait for {} to exist\n", path);
}