From: Carl N Baldwin Date: Thu, 10 Nov 2005 16:45:39 +0000 (-0700) Subject: Sort leftovers by last backup date THEN BY decreasing filesize. X-Git-Tag: release-0.4~15^2~5 X-Git-Url: http://git.pippins.net/embedvideo/.git/static/images/%7Blink_ppi%7D?a=commitdiff_plain;h=ddc36cb7ada4575030f31894eba76c3fc96e2826;p=backups%2F.git Sort leftovers by last backup date THEN BY decreasing filesize. --- diff --git a/main.cpp b/main.cpp index fb7d522..8540adf 100644 --- a/main.cpp +++ b/main.cpp @@ -177,12 +177,13 @@ int main() { unsigned long long modified_blocks, modified_bytes; sizes( modified_v.begin(), modified_v.end(), modified_blocks, modified_bytes ); - // Now, sort the backups by filesize and build a list that'll fit on a DVD + // Now, sort the backups by filesize (decreasing) and build a list that'll fit + // on a DVD file_vector backups_s; copy( backups.begin(), backups.end(), back_inserter( backups_s ) ); FileDataSizeCmp sizecmp; - sort( backups_s.begin(), backups_s.end(), sizecmp ); + sort( backups_s.rbegin(), backups_s.rend(), sizecmp ); file_set final; unsigned long long space = 0x100000000ULL; @@ -191,13 +192,15 @@ int main() { // Copy files over until full or out of files bool complete - = copy_until_full( backups_s.rbegin(), backups_s.rend(), final_i, space ); + = copy_until_full( backups_s.begin(), backups_s.end(), final_i, space ); // Track the size filled up by essential backups unsigned long long essential_blocks, essential_bytes; sizes( final.begin(), final.end(), essential_blocks, essential_bytes ); - // Now, sort the non-backed-up list by last_backup_date and back-fill + // Now, sort the non-backed-up list by last_backup_date, then by filesize + // (decreasing) and back-fill. This should minimize the number of DVDs in the + // collection left with actual content. if( 0 != space ) { file_vector leftovers; FileDataNameCmp cmp; @@ -207,7 +210,10 @@ int main() { cmp ); FileDataLastBackupCmp lastbackupcmp; - sort( leftovers.begin(), leftovers.end(), lastbackupcmp ); + // Achieve 'last back date then by filesize' by first sorting by filesizing + // and then running stable sort by last backup date. + sort( leftovers.rbegin(), leftovers.rend(), sizecmp ); + stable_sort( leftovers.begin(), leftovers.end(), lastbackupcmp ); copy_until_full( leftovers.begin(), leftovers.end(), final_i, space ); }