- // Now, sort the backup_list by filesize and build a list of up to SIZE
-
- // Now, sort the non-backed-up list my last_backup_date and back-fill
+ // Now, sort the backup_set by filesize and build a list of up to SIZE
+ file_vector backups_bysize;
+ copy( backup_set.begin(), backup_set.end(), back_inserter( backups_bysize ) );
+ FileDataSizeCmp sizecmp;
+ sort( backups_bysize.begin(), backups_bysize.end(), sizecmp );
+
+ file_set final_set;
+ unsigned long long bytes_available = 4700000000ULL; // 4.3 GBytes
+
+ unsigned long long block_size = 512ULL;
+
+ // Copy files over until full or out of files
+ file_vector::reverse_iterator i = backups_bysize.rbegin();
+ while( 0 != bytes_available && i != backups_bysize.rend() ) {
+ unsigned long long size = (*i)->getFileSize();
+ unsigned long long blocks = size & ( ~(block_size-1) );
+ if( blocks < size ) blocks += block_size;
+ if( blocks <= bytes_available ) {
+ bytes_available -= blocks;
+ final_set.insert( *i );
+ }
+ ++i;
+ }