ret = sendfile(outFd, inFd, 0, statSrc.st_size);
RUNNER_ASSERT_ERRNO_MSG(ret != -1, "sendfile failed");
+
+ ret = fsync(outFd);
+ RUNNER_ASSERT_ERRNO_MSG(ret != -1, "fsync failed");
}
void copyCynaraFiles(const std::string &source, const std::string &destination)
std::string tempSrc = source + "/" + direntPtr->d_name;
copyCynaraFile(tempSrc, tempDest);
}
+
+ syncDir(destination);
+}
+
+void syncElem(const std::string &filename, int flags, mode_t mode)
+{
+ int fileFd = TEMP_FAILURE_RETRY(open(filename.c_str(), flags, mode));
+ RUNNER_ASSERT_ERRNO_MSG(fileFd != -1, "open failed name=" << filename);
+ FdUniquePtr fdPtr(&fileFd);
+
+ int ret = fsync(fileFd);
+ RUNNER_ASSERT_ERRNO_MSG(ret != -1, "fsync failed name=" << filename);
+}
+
+void syncDir(const std::string &dirname, mode_t mode) {
+ syncElem(dirname, O_DIRECTORY, mode);
}
void makeDir(const std::string &directory)
{
RUNNER_ASSERT_ERRNO_MSG(!mkdir(directory.c_str(), S_IRWXU | S_IRWXG | S_IRWXO),
"Unable to make " << directory << " test directory");
+
+ syncDir(directory);
}
void removeDirFiles(const std::string &dir)
int ret = nftw(dir.c_str(), removeFile, 2, FTW_DEPTH | FTW_PHYS);
if (ret == -1)
RUNNER_ASSERT_ERRNO_MSG(errno == ENOENT, "nftw failed");
+ else
+ syncDir(dir);
}
void removeDirIfExists(const std::string &dir)