开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from duyanning/cpps
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (3)
标签 (5)
master
user-defined-rule
clang
v0.3.0
v0.2.0
v0.1.2
v0.1.1
v0.1.0
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (3)
标签 (5)
master
user-defined-rule
clang
v0.3.0
v0.2.0
v0.1.2
v0.1.1
v0.1.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (3)
标签 (5)
master
user-defined-rule
clang
v0.3.0
v0.2.0
v0.1.2
v0.1.1
v0.1.0
cpps
/
src
/
FileEntity.cpp
cpps
/
src
/
FileEntity.cpp
FileEntity.cpp 5.43 KB
一键复制 编辑 原始数据 按行查看 历史
duyanning 提交于 2019年07月28日 20:12 +08:00 . fix bug
#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 first
int 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;
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

C++脚本(伪)解释器/C++项目(零Makefile)构建系统引擎/支持GCC, MinGW, Visual C++, Clang Pseudo Interpreter for C++ Script / C++ Project Build System Engine with Zero Makefiles / Supporting GCC, MinGW, Visual C++, Clang
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/luozhiping/cpps.git
git@gitee.com:luozhiping/cpps.git
luozhiping
cpps
cpps
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /