projects
/
backups
/
.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c6cbff9
)
Some clean-up
author
Carl Baldwin
<cnb@ball.(none)>
Mon, 24 Oct 2005 21:47:17 +0000
(15:47 -0600)
committer
Carl Baldwin
<cnb@ball.(none)>
Mon, 24 Oct 2005 21:47:17 +0000
(15:47 -0600)
main.cpp
patch
|
blob
|
history
diff --git
a/main.cpp
b/main.cpp
index b0b6f1194e739ea632e0d273dd7bad63b8b3bcdc..d8a1214192108082e96fe2b78dd11a91e50065de 100644
(file)
--- a/
main.cpp
+++ b/
main.cpp
@@
-120,6
+120,21
@@
void copy_filenames( I begin, const I &end, O out ) {
}
}
}
}
+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;
int main() {
// Parse the list of current files on stdin
file_set current;
@@
-174,10
+189,8
@@
int main() {
insert_iterator<file_set> final_i( final, final.begin() );
// Copy files over until full or out of files
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;
// Track the size filled up by essential backups
unsigned long long essential_blocks, essential_bytes;
@@
-203,16
+216,14
@@
int main() {
sizes( final.begin(), final.end(), total_blocks, total_bytes );
unsigned long long now = current_time();
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 );
// 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
// 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;
cerr << now << endl << endl;
@@
-231,6
+242,6
@@
int main() {
if( ! complete ) { cerr << "Backup is incomplete!" << endl; }
// Clean-up
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() );
}
}