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.

64 lines
2.0 KiB

#include "tagmanifest.hpp"
#include "manifest.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 ) {
map<checksum_algorithms, string> possible_manifest_files;
possible_manifest_files[md5] = "tagmanifest-md5.txt";
possible_manifest_files[sha1] = "tagmanifest-sha1.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;
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[it->first] = filename;
}
}
}
map<string,string> Tagmanifest::get_checksum_file_pairs(checksum_algorithms alg) {
string filename = Tagmanifest::manifest_algorithm_files[ alg ];
map<string,string> checksum_file_pairs;
cout << "using file " << filename << endl;
ifstream file;
file.open( filename );
if (file.is_open()) {
string line;
while (getline(file, line)) {
stringstream line_ss ( line );
string checksum;
string subfile;
line_ss >> checksum;
line_ss >> subfile;
checksum_file_pairs[checksum]=subfile;
cout << "checksum="<<checksum<<" file="<<subfile<<endl;
}
file.close();
}
for (map<string,string>::iterator it=checksum_file_pairs.begin(); it!=checksum_file_pairs.end(); ++it) {
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;
}
}
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab