After creating, copying and removing files program should
wait on disc synchronization, otherwise test can fail, e.g.
when we swap database files and start cynara, which loads
old not-yet-synchronized version of db.
Change-Id: Ie5c26da859e4e2a88311bb68ed7a0138b98e87d7
ret = sendfile(outFd, inFd, 0, statSrc.st_size);
RUNNER_ASSERT_ERRNO_MSG(ret != -1, "sendfile failed");
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)
}
void copyCynaraFiles(const std::string &source, const std::string &destination)
std::string tempSrc = source + "/" + direntPtr->d_name;
copyCynaraFile(tempSrc, tempDest);
}
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");
}
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");
}
void removeDirFiles(const std::string &dir)
}
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");
int ret = nftw(dir.c_str(), removeFile, 2, FTW_DEPTH | FTW_PHYS);
if (ret == -1)
RUNNER_ASSERT_ERRNO_MSG(errno == ENOENT, "nftw failed");
}
void removeDirIfExists(const std::string &dir)
}
void removeDirIfExists(const std::string &dir)
#ifndef CYNARA_TEST_FILE_OPERATIONS_H
#define CYNARA_TEST_FILE_OPERATIONS_H
#ifndef CYNARA_TEST_FILE_OPERATIONS_H
#define CYNARA_TEST_FILE_OPERATIONS_H
#include <string>
namespace FileOperations
#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);
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);
void makeDir(const std::string &directory);
void removeDirFiles(const std::string &dir);
void removeDirIfExists(const std::string &dir);