@ -36,21 +36,21 @@ multimap<checksum_string_t,filename_t> Manifest::get_checksum_file_pairs(checksu
bool Manifest : : validate ( ) {
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 ) {
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 ( 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 ) ;
multimap < checksum_string_t , filename_t > checksum_file_pairs = this - > get_checksum_file_pairs ( manifest_algorithm_file . first ) ;
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;
if ( calc_checksum . empty ( ) ) {
this - > log < < " Bagit file ' " < < file < < " ', checksum ' " < < expected_checksum < < " ' is expected by file ' " < < it - > second < < " ', but file was not found " < < endl ;
this - > log < < " Bagit file ' " < < file < < " ', checksum ' " < < expected_checksum < < " ' is expected by file ' " < < manifest_algorithm_file . second < < " ', 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 ' " < < it - > second < < " ', 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 ;
is_valid = false ;
}
fs : : path p { file } ;
@ -69,7 +69,7 @@ bool Manifest::validate() {
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 ) {
for ( auto 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;
@ -77,10 +77,10 @@ void Manifest::debug() {
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 ;
for ( auto & manifest_algorithm_file : this - > manifest_algorithm_files ) {
multimap < checksum_string_t , filename_t > checksum_file_pairs = this - > get_checksum_file_pairs ( manifest_algorithm_file . first ) ;
for ( auto & checksum_file_pair : checksum_file_pairs ) {
string file = this - > basedir + checksum_file_pair . second ;
// cout << "MF: '" << file << "'" << endl;
files . push_back ( file ) ;
}
@ -88,13 +88,13 @@ list<string> Manifest::get_checksummed_files() {
return files ;
}
bool Manifest : : store ( string basedir , list < string > & files ) {
bool Manifest : : store ( const string & basedir , list < string > & files ) {
Checksum checksum ;
for ( map < checksum_algorithms , string > : : iterator it = this - > manifest_algorithm_files . begin ( ) ; it ! = this - > manifest_algorithm_files . end ( ) ; + + it ) {
checksum_algorithms alg = it - > first ;
for ( auto & manifest_algorithm_file : this - > manifest_algorithm_files ) {
checksum_algorithms alg = manifest_algorithm_file . first ;
// test if file exists
string algfilename = basedir + it - > second ;
cout < < " DEBUG manifest::store, file=' " < < algfilename < < " ' (newbase=' " < < basedir < < " ', filename=' " < < it - > second < < " ' " < < endl ;
string algfilename = basedir + manifest_algorithm_file . second ;
cout < < " DEBUG manifest::store, file=' " < < algfilename < < " ' (newbase=' " < < basedir < < " ', filename=' " < < manifest_algorithm_file . second < < " ' " < < endl ;
ofstream alg_txt_file ;
alg_txt_file . open ( algfilename ) ;
if ( alg_txt_file . is_open ( ) ) {