diff --git a/src/lib/bag.cpp b/src/lib/bag.cpp index c860457..b11373d 100644 --- a/src/lib/bag.cpp +++ b/src/lib/bag.cpp @@ -152,7 +152,9 @@ bool Bag::store( string basedir ) { bagit_txt_file.close(); } else { Bag::log << "file " << bagit_txt_path << "could not be open for writing" << endl; + return false; } + return true; } @@ -243,16 +245,18 @@ bool Bag::validate() { if (this->bagmetadata_p->has_oxum()) { // check oxum of payload Checksum c; - list files = this->payload_p->get_all_absolute_paths(); - oxum_t expected_oxum = this->bagmetadata_p->get_oxum(); - oxum_t calculated_oxum = c.oxum_of_filelist( files ); - if (expected_oxum.octetcount != calculated_oxum.octetcount) { - this->log << "Bagit payload oxum octectcount=" << to_string(expected_oxum.octetcount) << " expected, but " << to_string(calculated_oxum.octetcount) << " found" << endl; - is_valid = false; - } - if (expected_oxum.streamcount != calculated_oxum.streamcount) { - this->log << "Bagit payload oxum streamcount=" << to_string(expected_oxum.streamcount) << " expected, but " << to_string(calculated_oxum.streamcount) << " found" << endl; - is_valid = false; + if (this->payload_p != nullptr) { + list files = this->payload_p->get_all_absolute_paths(); + oxum_t expected_oxum = this->bagmetadata_p->get_oxum(); + oxum_t calculated_oxum = c.oxum_of_filelist( files ); + if (expected_oxum.octetcount != calculated_oxum.octetcount) { + this->log << "Bagit payload oxum octectcount=" << to_string(expected_oxum.octetcount) << " expected, but " << to_string(calculated_oxum.octetcount) << " found" << endl; + is_valid = false; + } + if (expected_oxum.streamcount != calculated_oxum.streamcount) { + this->log << "Bagit payload oxum streamcount=" << to_string(expected_oxum.streamcount) << " expected, but " << to_string(calculated_oxum.streamcount) << " found" << endl; + is_valid = false; + } } }