simplify isChecksumMatching, move to filesystem::path
parent
6191c69d74
commit
6e92f79c13
|
@ -6580,7 +6580,7 @@ DynamicModel::dynamicOnlyEquationsNbr() const
|
||||||
bool
|
bool
|
||||||
DynamicModel::isChecksumMatching(const string &basename, bool block) const
|
DynamicModel::isChecksumMatching(const string &basename, bool block) const
|
||||||
{
|
{
|
||||||
std::stringstream buffer;
|
stringstream buffer;
|
||||||
|
|
||||||
// Write equation tags
|
// Write equation tags
|
||||||
for (const auto & equation_tag : equation_tags)
|
for (const auto & equation_tag : equation_tags)
|
||||||
|
@ -6632,28 +6632,26 @@ DynamicModel::isChecksumMatching(const string &basename, bool block) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int result = hash<string>{}(buffer.str());
|
size_t result = hash<string>{}(buffer.str());
|
||||||
|
|
||||||
bool basename_dir_exists = !filesystem::create_directory(basename);
|
|
||||||
|
|
||||||
// check whether basename directory exist. If not, create it.
|
// check whether basename directory exist. If not, create it.
|
||||||
// If it does, read old checksum if it exist
|
// If it does, read old checksum if it exists, return if equal to result
|
||||||
fstream checksum_file;
|
fstream checksum_file;
|
||||||
string filename = basename + "/checksum";
|
auto filename = filesystem::path{basename} / "checksum";
|
||||||
unsigned int old_checksum = 0;
|
if (!filesystem::create_directory(basename))
|
||||||
// read old checksum if it exists
|
|
||||||
if (basename_dir_exists)
|
|
||||||
{
|
{
|
||||||
checksum_file.open(filename, ios::in | ios::binary);
|
checksum_file.open(filename, ios::in | ios::binary);
|
||||||
if (checksum_file.is_open())
|
if (checksum_file.is_open())
|
||||||
{
|
{
|
||||||
|
size_t old_checksum;
|
||||||
checksum_file >> old_checksum;
|
checksum_file >> old_checksum;
|
||||||
checksum_file.close();
|
checksum_file.close();
|
||||||
|
if (old_checksum == result)
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// write new checksum file if none or different from old checksum
|
// write new checksum file if none or different from old checksum
|
||||||
if (old_checksum != result)
|
|
||||||
{
|
|
||||||
checksum_file.open(filename, ios::out | ios::binary);
|
checksum_file.open(filename, ios::out | ios::binary);
|
||||||
if (!checksum_file.is_open())
|
if (!checksum_file.is_open())
|
||||||
{
|
{
|
||||||
|
@ -6663,9 +6661,6 @@ DynamicModel::isChecksumMatching(const string &basename, bool block) const
|
||||||
checksum_file << result;
|
checksum_file << result;
|
||||||
checksum_file.close();
|
checksum_file.close();
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue