C++ Library to handle BagIt structures. BagIt is a standard format to create transfer packages for digital preservation purposes. See https://en.wikipedia.org/wiki/BagIt for details
http://andreas-romeyke.de
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.7 KiB
92 lines
2.7 KiB
#include "bag.hpp"
|
|
|
|
|
|
|
|
|
|
bool Bag::validate( list<string> & log ) {
|
|
bool is_valid = true;
|
|
if (this->bagit_version_major != 0) {
|
|
log.push_back( "Bagit major version 0 is expected, but got: " + to_string(this->bagit_version_major));
|
|
is_valid = false;
|
|
}
|
|
if (this->bagit_version_minor != 97) {
|
|
log.push_back( "Bagit minor version 97 is expected, but got: " + to_string(this->bagit_version_minor));
|
|
is_valid = false;
|
|
}
|
|
if (0 != tag_file_character_encoding.compare( "UTF-8" )) {
|
|
log.push_back( "Bagit character encoding UTF-8 is expected, but got: " + this->tag_file_character_encoding);
|
|
is_valid = false;
|
|
}
|
|
if (NULL == this->payload_p) {
|
|
log.push_back( "Bagit payload directory 'data/' is expected, but could not found");
|
|
is_valid = false;
|
|
} else {
|
|
bool ret = this->payload_p->validate( log );
|
|
if (ret == false) {
|
|
is_valid = false;
|
|
}
|
|
}
|
|
if (NULL == this->payloadmanifest_p) {
|
|
is_valid = false;
|
|
} else {
|
|
log.push_back( "Bagit payload manifest");
|
|
bool ret = this->payloadmanifest_p->validate( log );
|
|
if (ret == false) {
|
|
is_valid = false;
|
|
}
|
|
}
|
|
// next elements are optional
|
|
if (NULL == this->tagmanifest_p) {
|
|
} else {
|
|
log.push_back( "Bagit tag manifest");
|
|
bool ret = this->tagmanifest_p->validate( log );
|
|
if (ret == false) {
|
|
is_valid = false;
|
|
}
|
|
}
|
|
if (NULL == this->bagmetadata_p) {
|
|
} else {
|
|
bool ret = this->bagmetadata_p->validate( log );
|
|
if (ret == false) {
|
|
is_valid = false;
|
|
}
|
|
if (this->bagmetadata_p->has_oxum()) {
|
|
// check oxum of payload
|
|
Checksum c;
|
|
list<string> files = this->payload_p->get_all_relative_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) {
|
|
log.push_back("Bagit payload oxum octectcount=" + to_string(expected_oxum.octetcount) + " expected, but " + to_string(calculated_oxum.octetcount) + " found");
|
|
is_valid = false;
|
|
}
|
|
if (expected_oxum.streamcount != calculated_oxum.streamcount) {
|
|
log.push_back("Bagit payload oxum streamcount=" + to_string(expected_oxum.streamcount) + " expected, but " + to_string(calculated_oxum.streamcount) + " found");
|
|
is_valid = false;
|
|
}
|
|
|
|
}
|
|
}
|
|
/*
|
|
if (NULL == this->fetchfile_p) {
|
|
} else {
|
|
bool ret = this->fetchfile_p->validate( log );
|
|
if (ret == false) {
|
|
is_valid = false;
|
|
}
|
|
}
|
|
|
|
if (NULL == this->othertags_p) {
|
|
} else {
|
|
bool ret = this->othertags_p->validate( log);
|
|
if (ret == false) {
|
|
is_valid = false;
|
|
}
|
|
}
|
|
*/
|
|
|
|
return is_valid;
|
|
}
|
|
|
|
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab
|
|
|