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)
#ifndef CYNARA_TEST_FILE_OPERATIONS_H
#define CYNARA_TEST_FILE_OPERATIONS_H
+#include <fcntl.h>
#include <string>
namespace FileOperations
bool dirExists(const std::string &directory);
void copyCynaraFile(const std::string &src, const std::string &dst);
void copyCynaraFiles(const std::string &source, const std::string &destination);
+void syncElem(const std::string &filename, int flags = O_RDONLY, mode_t mode = S_IRUSR | S_IWUSR);
+void syncDir(const std::string &dirname, mode_t mode = S_IRUSR | S_IWUSR);
void makeDir(const std::string &directory);
void removeDirFiles(const std::string &dir);
void removeDirIfExists(const std::string &dir);