From: Carl N Baldwin Date: Fri, 21 Oct 2005 14:58:44 +0000 (-0600) Subject: Better determined what should be backed up X-Git-Tag: release-0.4~83 X-Git-Url: http://git.pippins.net/embedvideo/.git/static/%27%20%20%20%20.%20%24GLOBALS%5B%27phpgw%27%5D-%3Elink%28%27inc/jquery/images/checkmark.gif?a=commitdiff_plain;h=7f06c56f69c8bfda925dd6b28d73201f0a7ea311;p=backups%2F.git Better determined what should be backed up --- diff --git a/filedata.cpp b/filedata.cpp index 31078ea..6b14517 100644 --- a/filedata.cpp +++ b/filedata.cpp @@ -75,3 +75,17 @@ istream &operator>>( istream &i, FileData &d ) { return i; } + +bool needs_backup( const FileData *before, const FileData *after ) { + assert( before->getFileName() == after->getFileName() ); + + if( after->getLastBackupDate() < after->getModifiedDate() ) return true; + + if( before->getFileType() != after->getFileType() ) return true; + if( before->getPermissions() != after->getPermissions() ) return true; + if( before->getUserName() != after->getUserName() ) return true; + if( before->getGroupName() != after->getGroupName() ) return true; + if( before->getFileSize() != after->getFileSize() ) return true; + + return false; +} diff --git a/filedata.hpp b/filedata.hpp index 6254674..b339f05 100644 --- a/filedata.hpp +++ b/filedata.hpp @@ -4,6 +4,7 @@ #include #include #include +#include class FileData { public: @@ -67,6 +68,8 @@ struct FileDataNameCmp { std::less cmp; }; +bool needs_backup( const FileData *before, const FileData *after ); + typedef std::set file_set; typedef std::vector file_vector; diff --git a/main.cc b/main.cc index e2864fd..07868bc 100644 --- a/main.cc +++ b/main.cc @@ -62,7 +62,7 @@ void populate_set( istream &in, SET &files ) { template 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(), @@ -79,6 +79,11 @@ void partition_sets( const SET ¤t, const SET &old, 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() { @@ -93,23 +98,8 @@ 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; @@ -117,14 +107,15 @@ int main() { // 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 ) );