87 int fdot = pfilename.find_last_of(
'.');
88 string ending = pfilename.substr(fdot);
91 if (ending ==
".fld" || ending ==
".chk" || ending ==
".rst")
93 TiXmlDocument *xmlFldFile;
94 fs::path pathfilename(pfilename);
96 if (fs::is_directory(pathfilename))
98 std::vector<fs::path> dirfiles;
101 copy(fs::directory_iterator(pathfilename), fs::directory_iterator(),
102 back_inserter(dirfiles));
104 xmlFldFile =
new TiXmlDocument;
107 for (
int i = 0; i < dirfiles.size(); ++i)
110 std::ifstream file(infile.c_str());
111 ASSERTL0(file.good(),
"Unable to open file: " + infile);
112 file >> (*xmlFldFile);
117 xmlFldFile =
new TiXmlDocument(pfilename);
118 xmlFldFile->LoadFile(pfilename);
122 TiXmlElement *vNektar = xmlFldFile->FirstChildElement(
"NEKTAR");
126 TiXmlNode *vMetaData = vNektar->FirstChild(
"Metadata");
131 vNektar->RemoveChild(vMetaData);
133 vNektar = vNektar->NextSiblingElement(
"NEKTAR");
136 filename = pfilename +
".tmp";
137 xmlFldFile->SaveFile(filename);
141 filename = pfilename;
145 std::ifstream testFile(filename.c_str(), std::ios::binary);
146 ASSERTL0(testFile.is_open(),
"Error opening file " + filename);
149 std::vector<char> fileContents((std::istreambuf_iterator<char>(testFile)),
150 std::istreambuf_iterator<char>());
153 unsigned char hash[20];
156 sha1::calc((
void *)&fileContents[0], fileContents.size(), hash);
162 return std::string(strhash);
167 boost::ignore_unused(pStdout, pStderr);
169 std::map<std::string, std::string>::iterator it;
175 if (!boost::iequals(filehash, it->second))
177 std::cerr <<
"Failed SHA1 hash test." << std::endl;
178 std::cerr <<
" Expected: " << it->second << std::endl;
179 std::cerr <<
" Result: " << filehash << std::endl;
189 boost::ignore_unused(pStdout, pStderr);
191 std::map<std::string, std::string>::iterator it;
201 TiXmlElement *file =
m_metric->FirstChildElement(
"file");
204 std::string filename = file->Attribute(
"filename");
207 TiXmlElement *
sha1 =
new TiXmlElement(
"sha1");
211 " in list of calculated"
215 file->LinkEndChild(
sha1);
216 file = file->NextSiblingElement(
"file");
void calc(const void *src, const int bytelength, unsigned char *hash)
Calculate the SHA1 hash of some data set.