Clean-up the scripts directory a little
[backups/.git] / main.cpp
index d00d8de3aa1f089710890acd71180eb0dff470da..b0b6f1194e739ea632e0d273dd7bad63b8b3bcdc 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -10,6 +10,7 @@
 using namespace std;
 
 static const unsigned int bytes_in_block = 0x800;
+static const char * dbname = "/var/lib/backups/backups.db";
 
 unsigned long long current_time() {
   unsigned long long rc = 0;
@@ -108,13 +109,24 @@ void sizes( ITER begin, const ITER &end, INT &numblocks, INT &numbytes ) {
   }
 }
 
+template<class I, class O>
+void copy_filenames( I begin, const I &end, O out ) {
+  while( begin != end ) {
+    string output = (*begin)->getFileName();
+    output.push_back( 0 );
+    *out = output;
+    ++out;
+    ++begin;
+  }
+}
+
 int main() {
   // Parse the list of current files on stdin
   file_set current;
   populate_set( cin, current );
 
   file_set backed_up;
-  ifstream db( "test.db" );
+  ifstream db( dbname );
   if( db && db.good() ) {
     populate_set( db, backed_up );
   }
@@ -132,7 +144,7 @@ int main() {
 
   // Track the total size of added files
   unsigned long long added_blocks, added_bytes;
-  sizes( backups.begin(), backups.end(), added_blocks, added_bytes );
+  sizes( added.begin(), added.end(), added_blocks, added_bytes );
 
   file_vector modified_files;
   // Backup files that have been modified
@@ -157,7 +169,7 @@ int main() {
   sort( backups_s.begin(), backups_s.end(), sizecmp );
 
   file_set final;
-  unsigned long long space = 0x102800000ULL;  // about 98% of 4220 MBytes
+  unsigned long long space = 0x100000000ULL; // After looking at how big the ISO can be and how many 1K blocks are left after formatting the filesystem I decided on an even 4GB target
 
   insert_iterator<file_set> final_i( final, final.begin() );
 
@@ -196,11 +208,13 @@ int main() {
   }
 
   // Write the 'current' list to the dbfile
-  ofstream dbout( "test.db" );
+  ofstream dbout( dbname );
   copy( current.begin(), current.end(), ostream_iterator<FileData*>( dbout, "" ) );
 
   // Write the 'final' list to stdout
-  copy( final.begin(), final.end(), ostream_iterator<FileData*>( cout, "" ) );
+  copy_filenames( final.begin(), final.end(), ostream_iterator<string>( cout, "" ) );
+
+  cerr << now << endl << endl;
 
   cerr << "Need backing up..." << endl;
   cerr << "    Added Bytes:            " << added_bytes << endl;