From d89bcc9c40555e602b8fa68b0ef14187f830b91b Mon Sep 17 00:00:00 2001 From: "art1@andreas-romeyke.de" Date: Sun, 3 Jun 2018 14:50:24 +0200 Subject: [PATCH] - fixed using multimap calling get_checksum_file_pairs() - added method get_checksummed_files() --- src/lib/manifest.cpp | 59 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/src/lib/manifest.cpp b/src/lib/manifest.cpp index c51528f..ff997e0 100644 --- a/src/lib/manifest.cpp +++ b/src/lib/manifest.cpp @@ -11,10 +11,10 @@ namespace fs = boost::filesystem; using namespace std; -map Manifest::get_checksum_file_pairs(checksum_algorithms alg) { +multimap Manifest::get_checksum_file_pairs(checksum_algorithms alg) { string filename = this->manifest_algorithm_files[ alg ]; - map checksum_file_pairs; - cout << "using file " << filename << endl; + multimap checksum_file_pairs; + // cout << "using file " << filename << endl; ifstream file; file.open( filename ); if (file.is_open()) { @@ -25,7 +25,7 @@ map Manifest::get_checksum_file_pairs(checksum_algorithms alg) { string subfile; line_ss >> checksum; line_ss >> subfile; - checksum_file_pairs[checksum]=subfile; + checksum_file_pairs.insert( pair(checksum,subfile) ); // cout << "checksum="<second) << " (" << (it->first) << ")" <checksum_file_pairs = this->get_checksum_file_pairs( it->first ); - for (map::iterator ch=checksum_file_pairs.begin(); ch!=checksum_file_pairs.end(); ++ch) { + //cout << "validate using file '"<< (it->second) << "' (" << (it->first) << ")" <checksum_file_pairs = this->get_checksum_file_pairs( it->first ); + for (multimap::iterator ch=checksum_file_pairs.begin(); ch!=checksum_file_pairs.end(); ++ch) { string expected_checksum = ch->first; string file = this->basedir + ch->second; string calc_checksum = checksum.checksum_of_file( file, it->first ); - // cout << "\t" << "file="<second +"', but file was not found"); + 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; - log.push_back( "Bagit file '" + file + "', checksum '" + expected_checksum + "' is expected, but found: '" + calc_checksum + "'"); + log.push_back( "Bagit file '" + file + "', checksum '" + expected_checksum + "' is expected by file '" + it->second +"', but found: '" + calc_checksum + "'"); is_valid = false; } + fs::path p{ file }; + fs::file_status s = fs::status( p ); + if (! fs::is_regular_file( p )) { + log.push_back("Bagit file '" + file + "' does not exists in '" + this->basedir + "'"); + } } } + //cout << "MANIFEST validate, calling debug()" << endl; + //this->debug(); + //cout << "MANIFEST validate, finished" << endl; + return is_valid; } +void Manifest::debug() { + //cout << "DEBUG: basedir='"<basedir<<"'"<::iterator it=this->manifest_algorithm_files.begin(); it!=this->manifest_algorithm_files.end(); ++it) { + // cout << "DEBUG:\tvalidate using file '"<< (it->second) << "' (" << (it->first) << ")" < Manifest::get_checksummed_files() { + list files; + for (map::iterator it=this->manifest_algorithm_files.begin(); it!=this->manifest_algorithm_files.end(); ++it) { + multimapchecksum_file_pairs = this->get_checksum_file_pairs( it->first ); + for (multimap::iterator ch=checksum_file_pairs.begin(); ch!=checksum_file_pairs.end(); ++ch) { + string file = this->basedir + ch->second; + // cout << "MF: '" << file << "'" << endl; + files.push_back( file ); + } + } + return files; +} + + + + + // vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab