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.

68 lines
2.7 KiB

#include "tagmanifest.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;
Tagmanifest::Tagmanifest( string basedir ) {
Tagmanifest::basedir = basedir;
map<checksum_algorithms, string> possible_manifest_files;
for (checksum_algorithms alg : checksum_algorithmsList) {
possible_manifest_files[alg] = "tagmanifest-" + string_of_algorithm( alg ) + ".txt";
}
for (map<checksum_algorithms, string>::iterator it=possible_manifest_files.begin(); it!=possible_manifest_files.end(); ++it) {
// debug
// cout << it->first << " => " << it->second << endl;
// test if file exists
//string filename = basedir + it->second;
string filename = it->second;
checksum_algorithms alg = it->first;
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)) {
Tagmanifest::manifest_algorithm_files[alg] = filename;
// debug
//cout << "TAGMANIFEST: alg="<< it->first << " => filename=" << it->second << endl;
//cout << "TAGMANIFEST2: alg="<< it->first << " => filename=" << filename << endl;
}
}
this->exist_manifest_files = !possible_manifest_files.empty();
//cout << "TAGMANIFEST constructor, calling debug()" << endl;
//this->debug();
//cout << "TAGMANIFEST constructor, finished" << endl;
}
multimap<checksum_string_t,filename_t> Tagmanifest::get_checksum_file_pairs(checksum_algorithms alg) {
//cout << "DEBUG: begin Tagmanifest::get_checksum_file_pairs" << endl;
multimap<checksum_string_t,filename_t> checksum_file_pairs = Manifest::get_checksum_file_pairs(alg);
//cout << "DEBUG: called super->get_checksum_file_pairs" << endl;
for (multimap<checksum_string_t,filename_t>::iterator it=checksum_file_pairs.begin(); it!=checksum_file_pairs.end(); ++it) {
// cout << "DEBUG: TAGMANIFEST found 'data/' in the beginning of file '"<<it->second<<"' in tagmanifest file '"<< this->manifest_algorithm_files[ alg] << endl;
if (it->second.find( "data/" ) == 0) {
cout << "found 'data/' in the beginning of file '"<<it->second<<"' in tagmanifest file '"<< this->manifest_algorithm_files[ alg] << endl;
}
}
//cout << "TAGMANIFEST get_checksum_file_pairs, calling debug()" << endl;
//this->debug();
//cout << "TAGMANIFEST get_checksum_file_pairs, finished" << endl;
return checksum_file_pairs;
}
bool Tagmanifest::has_tagmanifest() {
return this->exist_manifest_files;
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab