template<class SET>
void partition_sets( const SET ¤t, const SET &old,
- SET &added, SET &common, SET &deleted ) {
+ SET &added, SET &common, SET &old_common, SET &deleted ) {
FileDataNameCmp cmp;
set_difference( current.begin(), current.end(),
old.begin(), old.end(),
inserter( common, common.begin() ),
cmp );
+
+ set_union( old.begin(), old.end(),
+ common.begin(), common.end(),
+ inserter( old_common, old_common.begin() ),
+ cmp );
}
int main() {
}
// Now divide the two sets into three sets (added, deleted and common )
- file_set added, deleted, common;
- partition_sets( current, backed_up, added, common, deleted );
-
- { // This little block will copy the last_backup_date from the second set to the first
- FileDataNameCmp cmp;
-
- file_set common_with_dates;
- set_union( backed_up.begin(), backed_up.end(),
- current.begin(), current.end(),
- inserter( common_with_dates, common_with_dates.begin() ),
- cmp );
-
- file_set::iterator i = common.begin(), j = common_with_dates.begin();
- for( ; i != common.end(); ++i, ++j ) {
- (*i)->setLastBackupDate( (*j)->getLastBackupDate() );
- }
- }
+ file_set added, deleted, common, old_common;
+ partition_sets( current, backed_up, added, common, old_common, deleted );
// Now find the list of files to backup.
file_set backups;
// backup all added files
copy( added.begin(), added.end(), inserter( backups, backups.begin() ) );
- // backup common files that have changed since the last backup date.
- for( file_set::iterator i = common.begin(); i != common.end(); ++i ) {
- if( (*i)->getLastBackupDate() < (*i)->getModifiedDate() ) {
- backups.insert( *i );
- }
+ // Backup files that have been modified
+ file_set::iterator i = common.begin(), j = old_common.begin();
+ for( ; i != common.end(); ++i, ++j ) {
+ (*i)->setLastBackupDate( (*j)->getLastBackupDate() );
+
+ if( needs_backup( *j, *i ) ) backups.insert( *i );
}
- // Now, sort the backups by filesize and build a list of up to SIZE
+ // Now, sort the backups by filesize and build a list that'll fit on a DVD
file_vector backups_s;
copy( backups.begin(), backups.end(), back_inserter( backups_s ) );