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.

52 lines
1.7 KiB

  1. // Copyright (C) 2018 Andreas Romeyke (art1@andreas-romeyke.de), 2018.
  2. //
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. #include "bag.hpp"
  16. using namespace std;
  17. #include <iostream>
  18. #include <string>
  19. int main(int argc, const char *argv[]) {
  20. if (argc != 3) {
  21. cout << "you need at least two arguments:" << endl;
  22. cout << "\t<bagit> a target dir" << endl;
  23. cout << "\t<data> a source dir" << endl;
  24. exit(-1);
  25. }
  26. const string bagit_dir = argv[1];
  27. const string data_dir = argv[2];
  28. Bag bag( bagit_dir );
  29. bag.reset_logstream();
  30. Payload payload( bagit_dir );
  31. payload.import_data_dir( data_dir );
  32. bag.add_payload( &payload );
  33. Bagmetadata bagmetadata( bagit_dir );
  34. Checksum checksum;
  35. oxum_t oxum = checksum.oxum_of_filelist( payload.get_all_absolute_paths() );
  36. bagmetadata.set_PayloadOxum( oxum );
  37. bagmetadata.set_SourceOrganization( "Test University" );
  38. bag.add_bagmetadata( &bagmetadata );
  39. bag.validate();
  40. bag.store();
  41. stringstream log;
  42. bag.get_logstream( log );
  43. cout << log.str() << endl;
  44. return 0;
  45. }
  46. // vim: set tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab