Browse Source

- fixed using multimap calling get_checksum_file_pairs()

- added method get_checksummed_files()
master
parent
commit
d89bcc9c40
1 changed files with 49 additions and 10 deletions
  1. +49
    -10
      src/lib/manifest.cpp

+ 49
- 10
src/lib/manifest.cpp View File

@ -11,10 +11,10 @@ namespace fs = boost::filesystem;
using namespace std;
map<string,string> Manifest::get_checksum_file_pairs(checksum_algorithms alg) {
multimap<checksum_string_t,filename_t> Manifest::get_checksum_file_pairs(checksum_algorithms alg) {
string filename = this->manifest_algorithm_files[ alg ];
map<string,string> checksum_file_pairs;
cout << "using file " << filename << endl;
multimap<checksum_string_t,filename_t> checksum_file_pairs;
// cout << "using file " << filename << endl;
ifstream file;
file.open( filename );
if (file.is_open()) {
@ -25,7 +25,7 @@ map<string,string> 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_string_t, filename_t>(checksum,subfile) );
// cout << "checksum="<<checksum<<" file="<<subfile<<endl;
}
file.close();
@ -37,20 +37,59 @@ bool Manifest::validate( list<string> & log ) {
Checksum checksum;
bool is_valid = true;
for (map<checksum_algorithms,string>::iterator it=this->manifest_algorithm_files.begin(); it!=this->manifest_algorithm_files.end(); ++it) {
cout << "validate using file "<< (it->second) << " (" << (it->first) << ")" <<endl;
map<string,string>checksum_file_pairs = this->get_checksum_file_pairs( it->first );
for (map<string,string>::iterator ch=checksum_file_pairs.begin(); ch!=checksum_file_pairs.end(); ++ch) {
//cout << "validate using file '"<< (it->second) << "' (" << (it->first) << ")" <<endl;
multimap<checksum_string_t,filename_t>checksum_file_pairs = this->get_checksum_file_pairs( it->first );
for (multimap<checksum_string_t,filename_t>::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="<<file <<" expected:"<<expected_checksum << " found: " << calc_checksum << endl;
if (0 != expected_checksum.compare( calc_checksum)) {
//cout << "\t" << "file="<<file <<" expected:"<<expected_checksum << " found: " << calc_checksum << endl;
if (calc_checksum.empty()) {
log.push_back( "Bagit file '" + file + "', checksum '" + expected_checksum + "' is expected by file '" + it->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='"<<this->basedir<<"'"<<endl;
//cout << "DEBUG: list of manifest files:"<<endl;
for (map<checksum_algorithms,string>::iterator it=this->manifest_algorithm_files.begin(); it!=this->manifest_algorithm_files.end(); ++it) {
// cout << "DEBUG:\tvalidate using file '"<< (it->second) << "' (" << (it->first) << ")" <<endl;
}
//cout << "DEBUG" << endl;
}
list<string> Manifest::get_checksummed_files() {
list<string> files;
for (map<checksum_algorithms,string>::iterator it=this->manifest_algorithm_files.begin(); it!=this->manifest_algorithm_files.end(); ++it) {
multimap<checksum_string_t,filename_t>checksum_file_pairs = this->get_checksum_file_pairs( it->first );
for (multimap<checksum_string_t,filename_t>::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

Loading…
Cancel
Save