From: Carl Baldwin Date: Mon, 24 Oct 2005 21:47:17 +0000 (-0600) Subject: Some clean-up X-Git-Tag: release-0.4~71 X-Git-Url: http://git.pippins.net/embedvideo/.git/%22%22.%24thumbnail.%22/%7Blink_ppi%7D?a=commitdiff_plain;h=de6a3235b4d319401d00db0e7975e2a57ed344b2;p=backups%2F.git Some clean-up --- diff --git a/main.cpp b/main.cpp index b0b6f11..d8a1214 100644 --- a/main.cpp +++ b/main.cpp @@ -120,6 +120,21 @@ void copy_filenames( I begin, const I &end, O out ) { } } +template +void updateLastBackupDate( ITER begin, const ITER &end, unsigned long long date ) { + while( begin != end ) { + (*begin)->setLastBackupDate( date ); + } +} + +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; @@ -174,10 +189,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; @@ -203,16 +216,14 @@ 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_filenames( final.begin(), final.end(), ostream_iterator( cout, "" ) ); + copy_filenames( final.begin(), final.end(), ostream_iterator( cout ) ); cerr << now << endl << endl; @@ -231,6 +242,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() ); }