Browse Source

- fixed basedir

- validate() checks for at least one checksum file
master
Andreas Romeyke 2 years ago
parent
commit
62f5651f96
1 changed files with 22 additions and 14 deletions
  1. +22
    -14
      src/lib/manifest.cpp

+ 22
- 14
src/lib/manifest.cpp View File

@@ -15,8 +15,9 @@ Manifest::Manifest( string basedir, string file_prefix ) {
Manifest::basedir = basedir;
Manifest::base_manifest_file_prefix = file_prefix;
map<checksum_algorithms, string> possible_manifest_files;
Manifest::exist_manifest_files = false;
for (checksum_algorithms alg : checksum_algorithmsList) {
possible_manifest_files[alg] = Manifest::base_manifest_file_prefix + string_of_algorithm( alg ) + ".txt";
possible_manifest_files[alg] = basedir + Manifest::base_manifest_file_prefix + string_of_algorithm( alg ) + ".txt";
}
for (auto & possible_manifest_file : possible_manifest_files) {
// debug
@@ -27,16 +28,16 @@ Manifest::Manifest( string basedir, string file_prefix ) {
checksum_algorithms alg = possible_manifest_file.first;
fs::path p{ filename };
fs::file_status s = fs::status( p );
cout << "path "<< p.string() << endl;
cout << "is file: "<< fs::is_regular_file( s) << endl;
this->log << "path "<< p.string() << endl;
this->log << "is file: "<< (fs::is_regular_file( s)?"yes":"no") << endl;
if (fs::is_regular_file( s)) {
Manifest::manifest_algorithm_files[alg] = filename;
Manifest::exist_manifest_files = true;
// debug
//cout << "TAGMANIFEST: alg="<< it->first << " => filename=" << it->second << endl;
//cout << "TAGMANIFEST2: alg="<< it->first << " => filename=" << filename << endl;
}
}
Manifest::exist_manifest_files = !possible_manifest_files.empty();
//cout << "TAGMANIFEST constructor, calling debug()" << endl;
//this->debug();
//cout << "TAGMANIFEST constructor, finished" << endl;
@@ -68,21 +69,29 @@ multimap<checksum_string_t,filename_t> Manifest::get_checksum_file_pairs(checksu
bool Manifest::validate() {
Checksum checksum;
bool is_valid = true;
bool at_least_one_manifest = false;
this->log << "validate exist manifestfiles = '"<< (this->exist_manifest_files?"yes":"no") <<endl;
this->log << "validate count = '"<< (this->manifest_algorithm_files.size()) <<endl;
for (auto & manifest_algorithm_file : this->manifest_algorithm_files) {
//cout << "validate using file '"<< (it->second) << "' (" << (it->first) << ")" <<endl;
multimap<checksum_string_t,filename_t>checksum_file_pairs = this->get_checksum_file_pairs( manifest_algorithm_file.first );
string manifest_file = manifest_algorithm_file.second;
checksum_algorithms alg = manifest_algorithm_file.first;
fs::path p{ manifest_file };
if (fs::is_regular_file( p )) {
at_least_one_manifest=true;
}
this->log << "validate using file '"<< (manifest_file) <<endl;
multimap<checksum_string_t,filename_t>checksum_file_pairs = this->get_checksum_file_pairs( alg );
for (auto & checksum_file_pair : checksum_file_pairs) {
string expected_checksum = checksum_file_pair.first;
string file = this->basedir + checksum_file_pair.second;
string calc_checksum = checksum.checksum_of_file( file, manifest_algorithm_file.first );
//cout << "\t" << "file="<<file <<" expected:"<<expected_checksum << " found: " << calc_checksum << endl;
string calc_checksum = checksum.checksum_of_file( file, alg );
if (calc_checksum.empty()) {
this->log << "Bagit file '" << file << "', checksum '" << expected_checksum << "' is expected by file '" << manifest_algorithm_file.second << "', but file was not found" << endl;
this->log << "Bagit file '" << file << "', checksum '" << expected_checksum << "' is expected by file '" << manifest_file << "', but file was not found" << endl;
is_valid = false;
}
else if (0 != expected_checksum.compare( calc_checksum)) {
// cout << ( "Bagit file '" + file + "', checksum '" + expected_checksum + "' is expected, but found: '" + calc_checksum + "'") << endl;
this->log << "Bagit file '" << file << "', checksum '" << expected_checksum << "' is expected by file '" << manifest_algorithm_file.second << "', but found: '" << calc_checksum << "'" << endl;
this->log << "Bagit file '" << file << "', checksum '" << expected_checksum << "' is expected by file '" << manifest_file << "', but found: '" << calc_checksum << "'" << endl;
is_valid = false;
}
fs::path p{ file };
@@ -92,9 +101,8 @@ bool Manifest::validate() {
}
}
}
//cout << "MANIFEST validate, calling debug()" << endl;
//this->debug();
//cout << "MANIFEST validate, finished" << endl;
if (! at_least_one_manifest) { is_valid = false; } // at least one manifest is needed!
cout << "MANIFESTLOG:" << this->log.str() << endl;

return is_valid;
}


Loading…
Cancel
Save