1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include "log/filesystem_ops.h"
#include <errno.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
namespace cert_trans {
int BasicFilesystemOps::mkdir(const std::string& path, mode_t mode) {
return ::mkdir(path.c_str(), mode);
}
int BasicFilesystemOps::remove(const std::string& path) {
return ::remove(path.c_str());
}
int BasicFilesystemOps::rename(const std::string& old_name,
const std::string& new_name) {
return ::rename(old_name.c_str(), new_name.c_str());
}
int BasicFilesystemOps::access(const std::string& path, int amode) {
return ::access(path.c_str(), amode);
}
FailingFilesystemOps::FailingFilesystemOps(int fail_point)
: op_count_(0), fail_point_(fail_point) {
}
int FailingFilesystemOps::mkdir(const std::string& path, mode_t mode) {
if (fail_point_ == op_count_++) {
errno = EIO;
return -1;
}
return BasicFilesystemOps::mkdir(path, mode);
}
int FailingFilesystemOps::remove(const std::string& path) {
if (fail_point_ == op_count_++) {
errno = EIO;
return -1;
}
return BasicFilesystemOps::remove(path);
}
int FailingFilesystemOps::rename(const std::string& old_name,
const std::string& new_name) {
if (fail_point_ == op_count_++) {
errno = EIO;
return -1;
}
return BasicFilesystemOps::rename(old_name, new_name);
}
int FailingFilesystemOps::access(const std::string& path, int amode) {
if (fail_point_ == op_count_++) {
errno = EACCES;
return -1;
}
return BasicFilesystemOps::access(path, amode);
}
} // namespace cert_trans
|