28 #include <sys/types.h> 45 #if defined HAVE_NFTW && !defined __MINGW32__ 56 int res = system(cmd.c_str());
58 string msg =
"system(\"";
60 msg +=
"\") failed, returning ";
67 void cp_R(
const std::string &src,
const std::string &dest) {
73 string cmd(
"xcopy /E /q /Y");
93 #if defined HAVE_NFTW && !defined __MINGW32__ 96 rm_rf_nftw_helper(
const char* path,
101 int r = (type == FTW_DP ? rmdir(path) : unlink(path));
105 return r < 0 ? errno : 0;
111 void rm_rf(
const string &filename) {
113 if (filename.empty() || !
dir_exists(filename))
116 #if defined HAVE_NFTW && !defined __MINGW32__ 117 auto flags = FTW_DEPTH | FTW_PHYS;
120 int eno = nftw(filename.c_str(), rm_rf_nftw_helper, 10, flags);
128 if (!(eno == EEXIST || eno == ENOTEMPTY) || --retries == 0) {
129 string msg =
"recursive delete of \"";
131 msg +=
"\") failed, errno = ";
145 string cmd(
"rd /s /q");
147 string cmd(
"rm -rf");
155 void touch(
const string &filename) {
156 int fd =
open(filename.c_str(), O_CREAT|O_WRONLY|
O_BINARY, 0644);
157 if (fd >= 0)
close(fd);
Convert errno value to std::string, thread-safe if possible.
void sleep(double t)
Sleep until the time represented by this object.
C++ function versions of useful Unix commands.
WritableDatabase open()
Construct a WritableDatabase object for a new, empty InMemory database.
Convert types to std::string.
Utility functions for testing files.
void rm_rf(const string &filename)
Remove a directory and contents, just like the Unix "rm -rf" command.
Append filename argument to a command string with suitable escaping.
void cp_R(const std::string &src, const std::string &dest)
Recursively copy a directory.
void errno_to_string(int e, string &s)
string str(int value)
Convert int to std::string.
bool dir_exists(const char *path)
Test if a directory exists.
<unistd.h>, but with compat.
static bool append_filename_argument(std::string &cmd, const std::string &arg, bool leading_space=true)
Append filename argument arg to command cmd with suitable escaping.
static void checked_system(const string &cmd)
Call system() and throw exception if it fails.
include <fcntl.h>, but working around broken platforms.
void touch(const string &filename)
Touch a file, just like the Unix "touch" command.