提交 5391e33d authored 作者: blu's avatar blu

big refacting of communitation architect

上级 fdcf06ff
......@@ -9,7 +9,8 @@
using namespace std;
int test_last_write_time(){
int test_last_write_time()
{
fs::path p = fs::current_path() / "example.bin";
std::ofstream(p.c_str()).put('a'); // create file
auto ftime = fs::last_write_time(p);
......@@ -29,19 +30,20 @@ int test_last_write_time(){
return 0;
}
void ftime2ctime(fs::file_time_type ftime){
void ftime2ctime(fs::file_time_type ftime)
{
std::time_t cftime = decltype(ftime)::clock::to_time_t(ftime);
std::cout << "\t\twt: " << std::asctime(std::localtime(&cftime)) << std::endl;
std::cout << "\t\twt: " << std::asctime(std::localtime(&cftime)) << std::endl;
}
vector<long> LoadVideoFiles(string path, int days, map<long, string> &ts2fileName, list<long> &tsRing, list<long> &tsNeedProc) {
vector<long> LoadVideoFiles(string path, int days, map<long, string> &ts2fileName, list<long> &tsRing, list<long> &tsNeedProc)
{
vector<long> v;
// get current timestamp
auto now = chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count();
try{
for (const auto & entry : fs::directory_iterator(path))
{
try {
for (const auto & entry : fs::directory_iterator(path)) {
if(entry.file_size() == 0 || !entry.is_regular_file()||entry.path().extension() != ".mp4") {
spdlog::warn("LoasdVideoFiles skipped {} (empty/directory/!mp4)", entry.path().c_str());
continue;
......@@ -49,38 +51,40 @@ vector<long> LoadVideoFiles(string path, int days, map<long, string> &ts2fileNam
auto ftime = fs::last_write_time(entry.path());
auto ts = decltype(ftime)::clock::to_time_t(ftime);
// check it was processed already
// check if processed already
if(ts2fileName.count(ts) != 0) {
spdlog::warn("LoasdVideoFiles multiple files with same timestamp: {}, {}(skipped), ", ts2fileName[ts], entry.path().c_str());
continue;
}
// check it was old files
// check old files
if(ts - now > days * 24 * 60 * 60) {
spdlog::info("file {} old that {} days", entry.path().c_str(), days);
tsNeedProc.push_back(ts);
}
else{
else {
tsRing.insert(std::lower_bound(tsRing.begin(), tsRing.end(), ts), ts);
}
// add to map
ts2fileName[ts] = entry.path();
}
}catch(exception &e) {
}
catch(exception &e) {
spdlog::error("LoasdVideoFiles exception : {}", e.what());
}
return v;
}
int main(int argc, const char *argv[]) {
int main(int argc, const char *argv[])
{
std::string path = argv[1];
list<long> tsRing;
list<long> tsProcess;
map<long, string> ts2fileName;
LoadVideoFiles(path, 2, ts2fileName, tsRing, tsProcess);
for(auto &i:tsRing) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论