X-Git-Url: http://git.pippins.net/embedvideo/.git/?a=blobdiff_plain;f=main.cpp;h=c7ae3876fbb13f84226cf415cc29825c862b21b7;hb=57409dee8819cc504d47a2f27b8937091244ed13;hp=945cc0d0b36c91de96147dddb469355a87e89d75;hpb=8482590d4b4c8158ba05815c8f62c74a4d5a591f;p=backups%2F.git diff --git a/main.cpp b/main.cpp index 945cc0d..c7ae387 100644 --- a/main.cpp +++ b/main.cpp @@ -10,7 +10,7 @@ using namespace std; static const unsigned int bytes_in_block = 0x800; -static const char * dbname = "/var/tmp/backups.db"; +static const char * dbname = "/var/lib/backups/backups.db"; unsigned long long current_time() { unsigned long long rc = 0; @@ -109,6 +109,33 @@ void sizes( ITER begin, const ITER &end, INT &numblocks, INT &numbytes ) { } } +template +void copy_filenames( I begin, const I &end, O out ) { + while( begin != end ) { + string output = (*begin)->getFileName(); + output.push_back( 0 ); + *out = output; + ++out; + ++begin; + } +} + +template +void updateLastBackupDate( ITER begin, const ITER &end, unsigned long long date ) { + while( begin != end ) { + (*begin)->setLastBackupDate( date ); + ++begin; + } +} + +template +void delete_objects( ITER begin, const ITER &end ) { + while( begin != end ) { + delete *begin; + ++begin; + } +} + int main() { // Parse the list of current files on stdin file_set current; @@ -133,7 +160,7 @@ int main() { // Track the total size of added files unsigned long long added_blocks, added_bytes; - sizes( backups.begin(), backups.end(), added_blocks, added_bytes ); + sizes( added.begin(), added.end(), added_blocks, added_bytes ); file_vector modified_files; // Backup files that have been modified @@ -163,10 +190,8 @@ int main() { insert_iterator final_i( final, final.begin() ); // Copy files over until full or out of files - bool complete = copy_until_full( backups_s.rbegin(), - backups_s.rend(), - final_i, - space ); + bool complete + = copy_until_full( backups_s.rbegin(), backups_s.rend(), final_i, space ); // Track the size filled up by essential backups unsigned long long essential_blocks, essential_bytes; @@ -192,16 +217,16 @@ int main() { sizes( final.begin(), final.end(), total_blocks, total_bytes ); unsigned long long now = current_time(); - for( file_set::iterator k = final.begin(); k != final.end(); ++k ) { - (*k)->setLastBackupDate( now ); - } + updateLastBackupDate( final.begin(), final.end(), now ); // Write the 'current' list to the dbfile ofstream dbout( dbname ); - copy( current.begin(), current.end(), ostream_iterator( dbout, "" ) ); + copy( current.begin(), current.end(), ostream_iterator( dbout ) ); // Write the 'final' list to stdout - copy( final.begin(), final.end(), ostream_iterator( cout, "" ) ); + copy_filenames( final.begin(), final.end(), ostream_iterator( cout ) ); + + cerr << now << endl << endl; cerr << "Need backing up..." << endl; cerr << " Added Bytes: " << added_bytes << endl; @@ -218,6 +243,6 @@ int main() { if( ! complete ) { cerr << "Backup is incomplete!" << endl; } // Clean-up - for( file_set::iterator i = backed_up.begin(); i != backed_up.end(); ++i ) { delete *i; } - for( file_set::iterator i = current.begin(); i != current.end(); ++i ) { delete *i; } + delete_objects( backed_up.begin(), backed_up.end() ); + delete_objects( current.begin(), current.end() ); }