}
}
+template<class ITER>
+void updateLastBackupDate( ITER begin, const ITER &end, unsigned long long date ) {
+ while( begin != end ) {
+ (*begin)->setLastBackupDate( date );
+ }
+}
+
+template<class ITER>
+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;
insert_iterator<file_set> 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;
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<FileData*>( dbout, "" ) );
+ copy( current.begin(), current.end(), ostream_iterator<FileData*>( dbout ) );
// Write the 'final' list to stdout
- copy_filenames( final.begin(), final.end(), ostream_iterator<string>( cout, "" ) );
+ copy_filenames( final.begin(), final.end(), ostream_iterator<string>( cout ) );
cerr << now << endl << endl;
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() );
}