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.

49 lines
1.8 KiB

#include "payloadmanifest.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <boost/filesystem.hpp>
//#include <filesystem> // c++17
//namespace fs = std::filesystem;
namespace fs = boost::filesystem;
using namespace std;
Payloadmanifest::Payloadmanifest( string basedir ) {
Payloadmanifest::basedir = basedir;
map<checksum_algorithms, string> possible_manifest_files;
possible_manifest_files[md5] = "manifest-md5.txt";
possible_manifest_files[sha1] = "manifest-sha1.txt";
for (map<checksum_algorithms, string>::iterator it=possible_manifest_files.begin(); it!=possible_manifest_files.end(); ++it) {
// test if file exists
string filename = basedir + it->second;
fs::path p{ filename };
fs::file_status s = fs::status( p );
// cout << "path "<< p.string() << endl;
// cout << "is file: "<< fs::is_regular_file( s) << endl;
if (fs::is_regular_file( s)) {
Payloadmanifest::manifest_algorithm_files[it->first] = filename;
// debug
cout << "PAYLOADMANIFEST: alg="<< it->first << " => filename=" << it->second << endl;
// cout << " alg="<< it->first << " => filename=" << Payloadmanifest::manifest_algorithm_files[it->first] << endl;
}
}
}
bool Payloadmanifest::validate( list<string> & log ) {
bool is_valid = true;
bool tmp = Manifest::validate( log );
if (false == tmp) { is_valid = false; }
// check if at least one payload file exist
cout << "payload_manifest: " << this->manifest_algorithm_files.size() << endl;
if (0 == this->manifest_algorithm_files.size()) {
log.push_back("Bagit payloadmanifest count greater zero expected, but " + to_string(this->manifest_algorithm_files.size()) + " found");
is_valid = false;
}
return is_valid;
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab