ClickHouse/src/Common/FileUpdatesTracker.h

39 lines
804 B
C++
Raw Normal View History

#pragma once
#include <Poco/Timestamp.h>
#include <string>
2021-04-30 20:16:35 +00:00
#include <filesystem>
2021-04-30 20:16:35 +00:00
namespace fs = std::filesystem;
class FileUpdatesTracker
{
private:
std::string path;
Poco::Timestamp known_time;
public:
FileUpdatesTracker(const std::string & path_)
: path(path_)
, known_time(0)
{}
bool isModified() const
{
return getLastModificationTime() > known_time;
}
void fixCurrentVersion()
{
known_time = getLastModificationTime();
}
private:
Poco::Timestamp getLastModificationTime() const
{
2021-04-30 20:16:35 +00:00
fs::file_time_type fs_time = fs::last_write_time(path);
auto micro_sec = std::chrono::duration_cast<std::chrono::microseconds>(fs_time.time_since_epoch());
return Poco::Timestamp(micro_sec.count());
}
};