Browse Source

- refactoring, using base class Manifest for Tagmanifest and Payloadmanifest

master
parent
commit
60145a92dd
7 changed files with 37 additions and 51 deletions
  1. +3
    -2
      src/include/bag.hpp
  2. +0
    -2
      src/include/manifest.hpp
  3. +18
    -0
      src/include/payloadmanifest.hpp
  4. +4
    -3
      src/include/tagmanifest.hpp
  5. +2
    -2
      src/lib/load_bag.cpp
  6. +0
    -20
      src/lib/manifest.cpp
  7. +10
    -22
      src/lib/tagmanifest.cpp

+ 3
- 2
src/include/bag.hpp View File

@ -2,8 +2,9 @@
#define LIBCBAG
#include <string>
#include <sstream>
#include "payload.hpp"
#include "manifest.hpp"
#include "payload.hpp"
#include "payloadmanifest.hpp"
#include "tagmanifest.hpp"
#include "bagmetadata.hpp"
#include "fetchfile.hpp"
@ -20,7 +21,7 @@ class Bag {
int bagit_version_minor;
string tag_file_character_encoding;
class Payload *payload_p;;
class Manifest *manifest_p; // TODO: list of manifests
class Payloadmanifest *payloadmanifest_p; // TODO: list of manifests
class Tagmanifest *tagmanifest_p; // TODO: list of tag manifests, optional
class Bagmetadata *bagmetadata_p;
class Fetchfile *fetchfile_p;


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

@ -5,12 +5,10 @@
#include "checksum.hpp"
using namespace std;
class Manifest{
private:
map<checksum_algorithms,string> manifest_algorithm_files;
public:
Manifest( string basedir );
map<string,string> get_checksum_file_pairs(checksum_algorithms algorithm);
};


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

@ -0,0 +1,18 @@
#ifndef LIBCBAG_PAYLOADMANIFEST
#define LIBCBAG_PAYLOADMANIFEST
#include <string>
#include <map>
#include "checksum.hpp"
#include "manifest.hpp"
using namespace std;
class Payloadmanifest : public Manifest {
private:
map<checksum_algorithms,string> manifest_algorithm_files;
public:
Payloadmanifest( string basedir );
};
#endif
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

+ 4
- 3
src/include/tagmanifest.hpp View File

@ -3,17 +3,18 @@
#include <string>
#include <map>
#include "checksum.hpp"
#include "manifest.hpp"
using namespace std;
class Tagmanifest {
class Tagmanifest : public Manifest {
private:
map<checksum_algorithms,string> manifest_algorithm_files;
bool exist_manifest_files;
public:
Tagmanifest( string basedir );
bool has_tagmanifest();
map<string,string> get_checksum_file_pairs(checksum_algorithms algorithm);
};
#endif


+ 2
- 2
src/lib/load_bag.cpp View File

@ -56,7 +56,7 @@ Bag::Bag( string dfname ) {
Bag::payload_p = new Payload( payloaddir ) ;
list<string> files = Bag::payload_p->get_all_relative_paths();
// read in payload manifest
Bag::manifest_p = new Manifest(dfname);
Bag::payloadmanifest_p = new Payloadmanifest(dfname);
// read in tagmanifest
Bag::tagmanifest_p = new Tagmanifest(dfname);
@ -65,7 +65,7 @@ Bag::Bag( string dfname ) {
cout << "file/dir (rel):" << (*i) << endl;
//cout << "file/dir (abs):" << (*i) << endl;
}
Bag::manifest_p->get_checksum_file_pairs( md5 );
Bag::payloadmanifest_p->get_checksum_file_pairs( md5 );
Bag::tagmanifest_p->get_checksum_file_pairs( md5 );
}


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

@ -11,26 +11,6 @@ namespace fs = boost::filesystem;
using namespace std;
Manifest::Manifest( string 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) {
// 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)) {
Manifest::manifest_algorithm_files[it->first] = filename;
}
}
}
map<string,string> Manifest::get_checksum_file_pairs(checksum_algorithms alg) {
string filename = Manifest::manifest_algorithm_files[ alg ];
map<string,string> checksum_file_pairs;


+ 10
- 22
src/lib/tagmanifest.cpp View File

@ -1,5 +1,4 @@
#include "tagmanifest.hpp"
#include "manifest.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
@ -30,35 +29,24 @@ Tagmanifest::Tagmanifest( string basedir ) {
Tagmanifest::manifest_algorithm_files[it->first] = filename;
}
}
this->exist_manifest_files = possible_manifest_files.empty();
}
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();
}
map<string,string> checksum_file_pairs = Manifest::get_checksum_file_pairs(alg);
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;
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;
}
}
}
return checksum_file_pairs;
}
bool Tagmanifest::has_tagmanifest() {
return this->exist_manifest_files;
}
// vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab

Loading…
Cancel
Save