remove metaprogramming

This commit is contained in:
Sebastian Messmer 2018-09-13 21:42:54 -07:00
parent 4430ca11e9
commit cb852c16cc
2 changed files with 5 additions and 29 deletions

View File

@ -10,7 +10,7 @@ public:
cpputils::unique_ref<fspp::File> CreateFileWithSize(const boost::filesystem::path &path, off_t size) { cpputils::unique_ref<fspp::File> CreateFileWithSize(const boost::filesystem::path &path, off_t size) {
auto file = this->CreateFile(path); auto file = this->CreateFile(path);
file->truncate(size); file->truncate(size);
assert(this->stat(*this->Load(path)).st_size == size); assert(this->stat(*this->Load(path)).size == size);
return file; return file;
} }
}; };

View File

@ -11,6 +11,7 @@
#include <cpp-utils/logging/logging.h> #include <cpp-utils/logging/logging.h>
#include <cpp-utils/pointer/unique_ref.h> #include <cpp-utils/pointer/unique_ref.h>
#include <cpp-utils/system/stat.h>
#include <sstream> #include <sstream>
using namespace fspp; using namespace fspp;
@ -138,33 +139,6 @@ void FilesystemImpl::closeFile(int descriptor) {
} }
namespace { namespace {
// Implementation taken from http://en.cppreference.com/w/cpp/types/void_t
// (it takes CWG1558 into account and also works for older compilers)
template<typename... Ts> struct make_void { typedef void type;};
template<typename... Ts> using void_t = typename make_void<Ts...>::type;
template<class Stat, class Enable = void> struct uses_timespec final : std::false_type {};
template<class Stat> struct uses_timespec<Stat, void_t<decltype(Stat().st_atim)>> final : std::true_type {};
// convert_stat_info_timestamps_ looks if struct ::stat has st_atim or st_atime members
// and sets the correct ones.
template<class Stat, class Enable = void> struct convert_stat_info_timestamps_ final {};
template<class Stat> struct convert_stat_info_timestamps_<Stat, std::enable_if_t<uses_timespec<Stat>::value>> final {
static void call(const fspp::Node::stat_info& input, Stat* output) {
output->st_atim = input.atime;
output->st_mtim = input.mtime;
output->st_ctim = input.ctime;
}
};
template<class Stat> struct convert_stat_info_timestamps_<Stat, std::enable_if_t<!uses_timespec<Stat>::value>> final {
static void call(const fspp::Node::stat_info& input, Stat* output) {
output->st_atime = input.atime.tv_sec;
output->st_mtime = input.mtime.tv_sec;
output->st_ctime = input.ctime.tv_sec;
}
};
void convert_stat_info_(const fspp::Node::stat_info& input, struct ::stat *output) { void convert_stat_info_(const fspp::Node::stat_info& input, struct ::stat *output) {
output->st_nlink = input.nlink; output->st_nlink = input.nlink;
output->st_mode = input.mode; output->st_mode = input.mode;
@ -172,7 +146,9 @@ void convert_stat_info_(const fspp::Node::stat_info& input, struct ::stat *outpu
output->st_gid = input.gid; output->st_gid = input.gid;
output->st_size = input.size; output->st_size = input.size;
output->st_blocks = input.blocks; output->st_blocks = input.blocks;
convert_stat_info_timestamps_<struct ::stat>::call(input, output); output->st_atim = input.atime;
output->st_mtim = input.mtime;
output->st_ctim = input.ctime;
} }
} }