X-Git-Url: http://git.pippins.net/embedvideo/.git/?a=blobdiff_plain;f=main.cpp;h=de22d91e28bb13388dd7dfd2b4b72863b0ee3288;hb=b1faa07ab41440b9af427937f43084d517c3dcf9;hp=d8a1214192108082e96fe2b78dd11a91e50065de;hpb=de6a3235b4d319401d00db0e7975e2a57ed344b2;p=backups%2F.git diff --git a/main.cpp b/main.cpp index d8a1214..de22d91 100644 --- a/main.cpp +++ b/main.cpp @@ -12,18 +12,17 @@ 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; - 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; +unsigned long long read_time( istream &i ) { + string date_string; + + int c; + // Todo, don't use char_traits directly here + for( c = i.get(); 0 != c && char_traits::eof() != c; c = i.get() ) { + date_string.push_back( c ); + } + if( char_traits::eof() == c ) { i.setstate( ios_base::eofbit ); } + + return atoll( date_string.c_str() ); } template @@ -105,7 +104,7 @@ void sizes( ITER begin, const ITER &end, INT &numblocks, INT &numbytes ) { numbytes += filesize; numblocks += blocks( filesize ); - begin++; + ++begin; } } @@ -124,6 +123,7 @@ template void updateLastBackupDate( ITER begin, const ITER &end, unsigned long long date ) { while( begin != end ) { (*begin)->setLastBackupDate( date ); + ++begin; } } @@ -136,6 +136,9 @@ void delete_objects( ITER begin, const ITER &end ) { } int main() { + // Get the date on stdin + unsigned long long now = read_time( cin ); + // Parse the list of current files on stdin file_set current; populate_set( cin, current ); @@ -215,7 +218,6 @@ int main() { unsigned long long total_blocks, total_bytes; sizes( final.begin(), final.end(), total_blocks, total_bytes ); - unsigned long long now = current_time(); updateLastBackupDate( final.begin(), final.end(), now ); // Write the 'current' list to the dbfile