|
|
@ -0,0 +1,70 @@ |
|
|
|
#include "bag.hpp"
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
// #include <boost/interprocess/detail/os_file_functions.hpp>
|
|
|
|
//#include <filesystem> // c++17
|
|
|
|
|
|
|
|
//namespace fs = std::filesystem;
|
|
|
|
namespace fs = boost::filesystem; |
|
|
|
using namespace std; |
|
|
|
|
|
|
|
bool Bag::store( string basedir ) { |
|
|
|
|
|
|
|
fs::path p{ basedir }; |
|
|
|
fs::file_status s = fs::status( p ); |
|
|
|
if (fs::is_directory( s)) { |
|
|
|
Bag::log << "directory already exists" << endl; |
|
|
|
return false; |
|
|
|
} |
|
|
|
fs::create_directory(p); |
|
|
|
|
|
|
|
// store payload
|
|
|
|
if (NULL == Bag::payload_p) { |
|
|
|
Bag::log << "Payload object needed" << endl; |
|
|
|
return false; |
|
|
|
} |
|
|
|
Bag::payload_p->store( basedir ); |
|
|
|
// store payload manifest
|
|
|
|
if (NULL == Bag::payloadmanifest_p) { |
|
|
|
Bag::log << "Payloadmanifest object needed" << endl; |
|
|
|
return false; |
|
|
|
} |
|
|
|
Bag::payloadmanifest_p->store( basedir ); |
|
|
|
// store tagmanifest
|
|
|
|
if (NULL == Bag::tagmanifest_p) { |
|
|
|
Bag::log << "Tagmanifest object needed" << endl; |
|
|
|
return false; |
|
|
|
} |
|
|
|
Bag::tagmanifest_p->store( basedir ); |
|
|
|
// store baginfo
|
|
|
|
if (NULL == Bag::bagmetadata_p) { |
|
|
|
Bag::log << "Bagmetadata object needed" << endl; |
|
|
|
return false; |
|
|
|
} |
|
|
|
Bag::bagmetadata_p->store( basedir ); |
|
|
|
// store fetchfile (if needed)
|
|
|
|
if (NULL == Bag::fetchfile_p) { |
|
|
|
Bag::log << "Fetchfile object needed" << endl; |
|
|
|
return false; |
|
|
|
} |
|
|
|
Bag::fetchfile_p->store( basedir ); |
|
|
|
// store other
|
|
|
|
if (NULL == Bag::othertags_p) { |
|
|
|
Bag::log << "Othertags object needed" << endl; |
|
|
|
return false; |
|
|
|
} |
|
|
|
Bag::othertags_p->store( basedir ); |
|
|
|
// store bag itself
|
|
|
|
string bagit_txt_path = basedir + "bagit.txt"; |
|
|
|
ofstream bagit_txt_file; |
|
|
|
bagit_txt_file.open( bagit_txt_path ); |
|
|
|
if (bagit_txt_file.is_open()) { |
|
|
|
bagit_txt_file << ("BagIt-Version: " + to_string(Bag::bagit_version_major) + "." + to_string(Bag::bagit_version_minor)) << endl; |
|
|
|
bagit_txt_file << ("Tag-File-Character-Encoding: " + Bag::tag_file_character_encoding) << endl; |
|
|
|
bagit_txt_file.close(); |
|
|
|
} else { |
|
|
|
Bag::log << "file " << bagit_txt_path << "could not be open for writing" << endl; |
|
|
|
} |
|
|
|
} |