X-Git-Url: http://git.pippins.net/embedvideo/.git/static/git-logo.png?a=blobdiff_plain;f=main.cpp;h=80385fe57651b2098dd9b8a70ba0117b6148b5d9;hb=c4767775f2f8882bdc28ecc6fc0e9d0c553577dd;hp=6dc5465e0d2089b2bce57a5a4ceb4f5a2dd55b3e;hpb=30e31c8d36fd4b0e12ab99fdcba347089000b0a7;p=backups%2F.git diff --git a/main.cpp b/main.cpp index 6dc5465..80385fe 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "filedata.hpp" @@ -30,7 +31,7 @@ template bool copy_until_full( I begin, I end, O out, INT &space ) { bool complete = true; - while( 0 != space && begin != end ) { + while( begin != end ) { INT size = (*begin)->getFileSize(); INT blocksize = blocks( size ) * bytes_in_block; @@ -136,7 +137,10 @@ void delete_objects( ITER begin, const ITER &end ) { int main() { // Check to make sure required env variables are set - if(getenv("backupdbin") == NULL || getenv("backupdbout") == NULL || getenv("blocksize") == NULL || getenv("availsizemb") == NULL) + if( getenv( "backupdbin" ) == NULL || + getenv( "backupdbout" ) == NULL || + getenv( "blocksize" ) == NULL || + getenv( "availsizemb" ) == NULL ) { cerr << "Required environment variables are not set. Exiting." << endl; return 1; @@ -195,8 +199,9 @@ int main() { sort( backups_s.rbegin(), backups_s.rend(), FileData::sizecmp ); file_set final; - unsigned long long space = atoll(getenv("availsizemb")) * 1048576ull; - + const unsigned long long availsizemb = atoll( getenv("availsizemb") ) * 0x100000ull; + unsigned long long space = availsizemb; + insert_iterator final_i( final, final.begin() ); // Copy files over until full or out of files @@ -230,9 +235,11 @@ int main() { sizes( final.begin(), final.end(), total_blocks, total_bytes ); // Track how many disks there are remaining to be burned - unsigned long long disks_remaining = 0; - if(modified_bytes || added_bytes) - disks_remaining = (unsigned long long)ceil(static_cast(modified_bytes+added_bytes)/(atoll(getenv("availsizemb"))*1048576ull))-1; + unsigned long long disks_remaining = 0; + if(modified_bytes || added_bytes) + disks_remaining = static_cast( + ceil( static_cast( modified_bytes + added_bytes ) / availsizemb ) - 1 + ); updateLastBackupDate( final.begin(), final.end(), now ); @@ -246,17 +253,17 @@ int main() { cerr << now << endl << endl; cerr << "Need backing up..." << endl; - cerr << " Added Bytes: " << added_bytes << endl; - cerr << " Added Blocks: " << added_blocks << endl; - cerr << " Modified Bytes: " << modified_bytes << endl; - cerr << " Modified Blocks: " << modified_blocks << endl; - cerr << " Disks Remaining: " << disks_remaining << endl << endl; + cerr << " Added Bytes: " << added_bytes << endl; + cerr << " Added Blocks: " << added_blocks << endl; + cerr << " Modified Bytes: " << modified_bytes << endl; + cerr << " Modified Blocks: " << modified_blocks << endl; + cerr << " Disks Remaining: " << disks_remaining << endl << endl; cerr << "Will be backed up..." << endl; - cerr << " Essential Bytes: " << essential_bytes << endl; - cerr << " Essential Blocks: " << essential_blocks << endl; - cerr << " Total Bytes: " << total_bytes << endl; - cerr << " Total Blocks: " << total_blocks << endl << endl; + cerr << " Essential Bytes: " << essential_bytes << endl; + cerr << " Essential Blocks: " << essential_blocks << endl; + cerr << " Total Bytes: " << total_bytes << endl; + cerr << " Total Blocks: " << total_blocks << endl << endl; if( ! complete ) { cerr << "Backup is incomplete!" << endl; }