-template<class ISTREAM, class SET>
-void populate_set( ISTREAM &in, SET &files ) {
+unsigned long long current_time() {
+ unsigned long long rc = 0;
+ time_t now_tt = time( 0 );
+ tm *now = localtime( &now_tt );
+ rc += ( now->tm_year + 1900ULL ) * 10000000000ULL;
+ rc += ( now->tm_mon + 1ULL ) * 100000000ULL;
+ rc += now->tm_mday * 1000000ULL;
+ rc += now->tm_hour * 10000ULL;
+ rc += now->tm_min * 100ULL;
+ rc += now->tm_sec;
+
+ return rc;
+}
+
+template<class I, class O>
+bool copy_until_full( I begin, I end, O out, unsigned long long &space ) {
+ const unsigned long long block_size = 0x200ULL;
+ bool complete = true;
+
+ I i = begin;
+ while( 0 != space && i != end ) {
+ unsigned long long size = (*i)->getFileSize();
+ unsigned long long blocks = size & ( ~(block_size-1) );
+ if( blocks < size ) blocks += block_size;
+
+ if( blocks <= space ) {
+ space -= blocks;
+ out = *i;
+ ++out;
+ } else {
+ // We missed a file that should be included so the backup is not complete
+ complete = false;
+ }
+ ++i;
+ }
+ return complete;
+}
+
+template<class SET>
+void populate_set( istream &in, SET &files ) {