Add a helper function for checking if a file exists.

This commit is contained in:
dg
2022-11-27 11:10:58 +00:00
parent 46ce882daa
commit 6d37fafb02
2 changed files with 9 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
#include "lib/bytes.h"
#include <fmt/format.h>
#include <iomanip>
#include <fstream>
bool emergencyStop = false;
@@ -190,3 +191,10 @@ std::string tohex(const std::string& s)
return ss.str();
}
bool doesFileExist(const std::string& filename)
{
std::ifstream f(filename);
return f.good();
}

View File

@@ -18,6 +18,7 @@ extern std::string toIso8601(time_t t);
extern std::string quote(const std::string& s);
extern std::string unhex(const std::string& s);
extern std::string tohex(const std::string& s);
extern bool doesFileExist(const std::string& filename);
/* If set, any running job will terminate as soon as possible (with an error).
*/