同步操作将从 duyanning/cpps 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "config.h"#include "global.h"#include "helpers.h"#include "FileEntity.h" // using Entity.cpp#include "Loggers.h"#include "Birthcert.h"#include "sha1.hpp"FileEntityPtr makeFileEntity(fs::path path){auto it = map_file_path_to_ptr.find(path.string());if (it != map_file_path_to_ptr.end()) {return it->second;}FileEntityPtr p{ new FileEntity(path) };map_file_path_to_ptr[path.string()] = p;return p;}FileEntity::FileEntity(fs::path path):m_path(path){}string FileEntity::name(){return m_path.string();}fs::path FileEntity::path(){return m_path;}bool FileEntity::update(){MINILOG(update_logger, "Entity::update: " << name());// 如果一个文件节点是个叶子节点if (prerequisiteList.empty()) {return exists(m_path); // 存在就好,不存在那就真没办法了}// 不是叶子节点的话,先把所有的下级节点更新一下DepInfo info;info.target = shared_from_this();info.all = prerequisiteList;updatePrerequisites(info);// 然后再判断是否要执行本节点关联的动作if (needExecuteActions(info)) {MINILOG(update_logger, "Entity::needExecuteActions: true " << name());return executeActions(info);}return true;}// 若文件不存在,就认为它的生日为0// 若它作为目标文件,生日为0意味着这是一个最古老的文件,它比任何依赖文件都要老,所以必须重新生成// 若它作为依赖文件,生日0意味着文件不存在,没法用它生成目标文件// todo:如果一个文件不存在,让这个函数抛出异常。// time_t FileEntity::timestamp()// {// time_t timestamp;// if (!exists(m_path))// timestamp = 0;// else {// // timestamp is the modification time of file// timestamp = last_write_time(m_path);// }// return timestamp;// }FileSig FileEntity::sig(){FileSig sig;sig.path = m_path;//cout << "cccccccccccccc\n";// sig.timestamp = last_write_time(m_path);// sig.size = file_size(m_path);sig.sha1 = SHA1::from_file(m_path.string());return sig;}// 判断是否需要执行关联的动作bool FileEntity::needExecuteActions(const DepInfo& info){//cout << "execing needExecuteActions" << this->path() << endl;// 如果本身还不存在,要重新生成if (!exists(path()))return true;// 如果有下级节点更新没成功,也去更新本节点,因为动作未必在乎if (!info.failed.empty())return true;// // 如果下级节点有变,它要重新生成// if (!info.changed.empty())// return true;// 如果没有下级节点,就不需要更新本节点if (prerequisiteList.empty())return false;// 有下级节点的,还要看一下下级结点跟自己出身证明上记录的是否一致// birthcert中记录的下级文件,可能少于.d中列出的下级文件。(这种情况发生在第一与第二次执行之间)fs::path birthcert_path = shadow(path());birthcert_path += ".birthcert";ifstream ifs(birthcert_path.string());//cout << "birthcert: " << birthcert_path.string() << endl;//assert(ifs);// .obj跟出生证明生死与共,但从.fl产生的.cxx文件在,其出生证明未必在。因为.cxx虽是自动生成,但不在cache中。if (!ifs)return true;boost::archive::text_iarchive ia(ifs);Birthcert birthcert;ia >> birthcert;for (auto p : prerequisiteList) {FileEntityPtr fp = static_pointer_cast<FileEntity>(p);if (birthcert.verifySig(fp->path().string(), fp->sig()) == false)return true;}return false;}void get_pre_file_paths_from_dep_file(fs::path dep_path, vector<fs::path>& pre_file_paths){ifstream f(dep_path.string());assert(f);if (!f)return;istream_iterator<string> i = istream_iterator<string>(f);// skip the firstint count = 0;while (count < 1) {if (*i != "\\")count++;++i;}for (; i != istream_iterator<string>(); ++i) {string t = *i;if (t != "\\") {fs::path p(t);pre_file_paths.push_back(p);}}}// (根据.d文件中指出的依赖关系)生成出生证明文件void FileEntity::generate_birth_cert(fs::path dep_path){vector<fs::path> pre_file_paths;get_pre_file_paths_from_dep_file(dep_path, pre_file_paths);generate_birth_cert(pre_file_paths);}void FileEntity::generate_birth_cert(){vector<fs::path> pre_file_paths;for (auto p : prerequisiteList) {if (p->isFile()) {FileEntityPtr f = static_pointer_cast<FileEntity>(p);pre_file_paths.push_back(f->path());}}generate_birth_cert(pre_file_paths);}void FileEntity::generate_birth_cert(const vector<fs::path>& pre_file_paths){Birthcert birthcert;for (auto p : pre_file_paths) {FileEntityPtr f = makeFileEntity(p);birthcert.addSig(f->path().string(), f->sig());}//cout << "before shadow: " << this->path() << endl;fs::path birthcert_path = shadow(this->path());//cout << "after shadow: " << birthcert_path << endl;birthcert_path += ".birthcert";ofstream ofs(birthcert_path.string());assert(ofs);boost::archive::text_oarchive oa(ofs);oa << birthcert;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。