Browse Source

- added store() to manifest

- added get_all_bag-files() to bag
master
Andreas Romeyke 3 years ago
parent
commit
7540ed726c
6 changed files with 40 additions and 19 deletions
  1. +1
    -0
      src/include/bag.hpp
  2. +1
    -1
      src/include/manifest.hpp
  3. +2
    -0
      src/include/payloadmanifest.hpp
  4. +13
    -2
      src/lib/bag.cpp
  5. +20
    -3
      src/lib/manifest.cpp
  6. +3
    -13
      src/lib/payloadmanifest.cpp

+ 1
- 0
src/include/bag.hpp View File

@ -30,6 +30,7 @@ class Bag {
public:
Bag();
Bag(string dfname);
list<string> get_all_bag_files();
bool store( string dfname);
bool validate();
void get_logstream( stringstream & log);


+ 1
- 1
src/include/manifest.hpp View File

@ -18,7 +18,7 @@ class Manifest{
list<filename_t> get_checksummed_files();
virtual bool validate();
void debug();
bool store( string basedir);
bool store( string basedir, list<string> & files);
void get_logstream( stringstream & log);
void reset_logstream();
};


+ 2
- 0
src/include/payloadmanifest.hpp View File

@ -1,6 +1,7 @@
#ifndef LIBCBAG_PAYLOADMANIFEST
#define LIBCBAG_PAYLOADMANIFEST
#include <string>
#include <list>
#include <map>
#include "checksum.hpp"
#include "manifest.hpp"
@ -11,6 +12,7 @@ class Payloadmanifest : public Manifest {
public:
Payloadmanifest( string basedir );
bool validate();
// bool store( string basedir, list<string> & files );
};
#endif


+ 13
- 2
src/lib/bag.cpp View File

@ -78,6 +78,15 @@ Bag::Bag( string dfname ) {
}
list<string> Bag::get_all_bag_files() {
list<string> files;
files.push_back( "bagit.txt" );
files.push_back( "bag-info.txt" );
if (NULL != this->tagmanifest_p) {
// TODO: this->tagmanifest_p->get_all_checksum_files()
}
return files;
}
bool Bag::store( string basedir ) {
@ -100,13 +109,15 @@ bool Bag::store( string basedir ) {
Bag::log << "Payloadmanifest object needed" << endl;
return false;
}
Bag::payloadmanifest_p->store( basedir );
list<string> payload_files =Bag::payload_p->get_all_relative_paths();
Bag::payloadmanifest_p->store( basedir, payload_files);
// store tagmanifest
if (NULL == Bag::tagmanifest_p) {
Bag::log << "Tagmanifest object needed" << endl;
return false;
}
Bag::tagmanifest_p->store( basedir );
list<string> bagfiles = Bag::get_all_bag_files();
Bag::tagmanifest_p->store( basedir, bagfiles );
// store baginfo
if (NULL == Bag::bagmetadata_p) {
Bag::log << "Bagmetadata object needed" << endl;


+ 20
- 3
src/lib/manifest.cpp View File

@ -88,11 +88,28 @@ list<string> Manifest::get_checksummed_files() {
return files;
}
bool Manifest::store( string basedir ) {
return false;
bool Manifest::store( string basedir, list<string>& files ) {
Checksum checksum;
for (map<checksum_algorithms, string>::iterator it=this->manifest_algorithm_files.begin(); it!=this->manifest_algorithm_files.end(); ++it) {
checksum_algorithms alg = it->first;
// test if file exists
string algfilename = basedir + it->second;
ofstream alg_txt_file;
alg_txt_file.open( algfilename );
if (alg_txt_file.is_open()) {
list<string>::iterator ch;
for (ch=files.begin(); ch!=files.end(); ++ch) {
string filename = *ch;
string checksum_string = checksum.checksum_of_file( filename, alg);
alg_txt_file << checksum_string << " " << filename << endl;
}
alg_txt_file.close();
}
}
return true;
}
void Manifest::get_logstream( stringstream & log ) {
log << this->log.rdbuf();
}


+ 3
- 13
src/lib/payloadmanifest.cpp View File

@ -19,22 +19,15 @@ Payloadmanifest::Payloadmanifest( string basedir ) {
possible_manifest_files[alg] = "manifest-" + string_of_algorithm( alg ) + ".txt";
}
for (map<checksum_algorithms, string>::iterator it=possible_manifest_files.begin(); it!=possible_manifest_files.end(); ++it) {
checksum_algorithms alg = it->first;
// 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;
Payloadmanifest::manifest_algorithm_files[alg] = filename;
}
}
//cout << "PAYLOADMANIFEST constructor, calling debug()" << endl;
//this->debug();
//cout << "PAYLOADMANIFEST constructor, finished" << endl;
}
bool Payloadmanifest::validate() {
@ -42,15 +35,12 @@ bool Payloadmanifest::validate() {
bool tmp = Manifest::validate();
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()) {
this->log << "Bagit payloadmanifest count greater zero expected, but " << to_string(this->manifest_algorithm_files.size()) << " found" << endl;
is_valid = false;
}
//cout << "PAYLOADMANIFEST validate, calling debug()" << endl;
//this->debug();
//cout << "PAYLOADMANIFEST validate, finished" << endl;
return is_valid;
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

Loading…
Cancel
Save