8 #include "filedata.hpp"
12 vector<string> split( const string &line, char c, int limit = -1 ) {
13 string::size_type start = 0, end = 0;
16 while( 0 != limit-- && end != line.size() ) {
20 end = line.find( c, start );
21 if( end == string::npos ) {
25 out.push_back( line.substr( start, end-start ) );
31 // Callback function for getting files from the database
32 int populate_set( void *files_v, int, char **vals, char ** ) {
33 file_set *files = reinterpret_cast<file_set*>( files_v );
34 files->insert( new FileData( vals[0][0],
47 file_set current_files;
49 // Parse the list of files on stdin
52 for( int c = cin.get(); 0 != c && ! cin.eof(); c = cin.get() ) {
53 file_string.push_back( c );
55 if( 0 != file_string.size() ) {
57 // type perms user group size datemodified name (7 total)
58 // f 0600 cnb cnb 424 20051015205340 ./.git/index
59 vector<string> vals = split( file_string, ' ', 7 );
60 current_files.insert( new FileData( vals[0][0],
64 atoi( vals[4].c_str() ),
65 atoi( vals[5].c_str() ),
68 } while( ! cin.eof() );
70 // Get the list of previously backed up files from the database.
73 const char *dbname = "test.db";
74 int rc = sqlite3_open( dbname, &db );
75 if( SQLITE_OK != rc ) {
76 cerr << "Cannot open database: " << dbname << ". Error message is..." << endl;
77 cerr << sqlite3_errmsg(db) << endl;
80 char *sqliteErrMsg = 0;
81 file_set previous_files;
82 rc = sqlite3_exec( db, "select * from filedata;", populate_set, &previous_files, &sqliteErrMsg );
83 if( SQLITE_OK != rc ) {
84 cerr << "Problem with database. Message is..." << endl;
85 cerr << sqliteErrMsg << endl;
90 for( file_set::iterator i = previous_files.begin(); i != previous_files.end(); ++i ) {
91 cout << (*i)->getFileName() << endl;
94 // Now divide the two sets into three sets (union and set differences)
98 set_difference( current_files.begin(), current_files.end(),
99 previous_files.begin(), previous_files.end(),
100 inserter( new_set, new_set.begin() ),
103 file_set deleted_set;
104 set_difference( previous_files.begin(), previous_files.end(),
105 current_files.begin(), current_files.end(),
106 inserter( deleted_set, deleted_set.begin() ),
109 // previous_files *should* definitely be the first set here
111 set_difference( previous_files.begin(), previous_files.end(),
112 current_files.begin(), current_files.end(),
113 inserter( common_set, common_set.begin() ),