Browse Source

- added first implementation

master
parent
commit
7e706ed485
1 changed files with 55 additions and 0 deletions
  1. +55
    -0
      src/lib/manifest.cpp

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

@ -0,0 +1,55 @@
#include "manifest.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <boost/filesystem.hpp>
//#include <filesystem> // c++17
//namespace fs = std::filesystem;
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;
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();
}
return checksum_file_pairs;
}
// vim: set tabstop=4

Loading…
Cancel
Save