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.
56 lines
1.5 KiB
56 lines
1.5 KiB
#include "payload.hpp"
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <list>
|
|
#include <boost/filesystem.hpp>
|
|
//#include <filesystem> // c++17
|
|
|
|
//namespace fs = std::filesystem;
|
|
namespace fs = boost::filesystem;
|
|
using namespace std;
|
|
Payload::Payload( string basedir ) {
|
|
fs::path p{ basedir };
|
|
fs::file_status s = fs::status( p );
|
|
cout << "basedir "<< p.string() << endl;
|
|
cout << "is dir: "<< fs::is_directory( s) << endl;
|
|
cout << "exists: "<< fs::exists(s) << endl;
|
|
this->basedir = basedir;
|
|
};
|
|
|
|
void Payload::scan_dir_recursively( fs::path directory, list<fs::path> &paths) {
|
|
fs::recursive_directory_iterator iter(directory), end;
|
|
for (; iter != end; ++iter) {
|
|
fs::path subdir = iter->path();
|
|
paths.push_back( subdir );
|
|
}
|
|
}
|
|
|
|
list<string> Payload::get_all_relative_paths() {
|
|
list<fs::path> paths;
|
|
list<string> strpaths;
|
|
fs::path directory(this->basedir);
|
|
Payload::scan_dir_recursively( directory, paths);
|
|
list<fs::path>::iterator i;
|
|
for (i=paths.begin(); i!= paths.end(); i++) {
|
|
strpaths.push_back( (*i).relative_path().string() );
|
|
}
|
|
return strpaths;
|
|
}
|
|
|
|
list<string> Payload::get_all_absolute_paths() {
|
|
list<fs::path> paths;
|
|
list<string> strpaths;
|
|
fs::path directory(this->basedir);
|
|
Payload::scan_dir_recursively( directory, paths);
|
|
list<fs::path>::iterator i;
|
|
for (i=paths.begin(); i!= paths.end(); i++) {
|
|
strpaths.push_back( (*i).string() );
|
|
}
|
|
return strpaths;
|
|
}
|
|
|
|
bool Payload::validate() {
|
|
// TODO
|
|
return true;
|
|
}
|
|
// vim: set tabstop=4
|