Revert unneeded and code style changes

progressbar_old
Vitaliy Filippov 2016-09-28 12:35:55 +03:00
parent c192d530e8
commit 33c39a5c6e
12 changed files with 35 additions and 48 deletions

View File

@ -45,7 +45,6 @@
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
const std::string client_id = "22314510474.apps.googleusercontent.com" ; const std::string client_id = "22314510474.apps.googleusercontent.com" ;
const std::string client_secret = "bl4ufi89h-9MkFlypcI7R785" ; const std::string client_secret = "bl4ufi89h-9MkFlypcI7R785" ;
@ -151,7 +150,7 @@ int Main( int argc, char **argv )
InitLog(vm) ; InitLog(vm) ;
Config config(vm) ; Config config(vm) ;
Log( "config file name %1%", config.Filename(), log::verbose ); Log( "config file name %1%", config.Filename(), log::verbose );
std::unique_ptr<http::Agent> http( new http::CurlAgent ); std::unique_ptr<http::Agent> http( new http::CurlAgent );
@ -183,7 +182,6 @@ int Main( int argc, char **argv )
config.Set( "refresh_token", Val( token.RefreshToken() ) ) ; config.Set( "refresh_token", Val( token.RefreshToken() ) ) ;
config.Save() ; config.Save() ;
} }
std::string refresh_token ; std::string refresh_token ;
try try
@ -216,17 +214,16 @@ int Main( int argc, char **argv )
if ( vm.count( "dry-run" ) == 0 ) if ( vm.count( "dry-run" ) == 0 )
{ {
//The progress bar should just be enabled when actual file transfers take place // The progress bar should just be enabled when actual file transfers take place
pb->SetShowProgressBar(true); pb->SetShowProgressBar( true ) ;
drive.Update() ; drive.Update() ;
pb->SetShowProgressBar(false); pb->SetShowProgressBar( false ) ;
drive.UpdateChangeStamp();
drive.SaveState() ; drive.SaveState() ;
} }
else else
drive.DryRun() ; drive.DryRun() ;
config.Save() ; config.Save() ;
Log( "Finished!", log::info ) ; Log( "Finished!", log::info ) ;
return 0 ; return 0 ;

View File

@ -92,8 +92,8 @@ void Drive::DetectChanges()
m_state.ResolveEntry() ; m_state.ResolveEntry() ;
} }
size_t Drive::getTotalChanges()
size_t Drive::getTotalChanges() { {
return m_state.getTotalChanges(); return m_state.getTotalChanges();
} }
@ -120,6 +120,8 @@ void Drive::Update()
{ {
Log( "Synchronizing files", log::info ) ; Log( "Synchronizing files", log::info ) ;
m_state.Sync( m_syncer, m_options ) ; m_state.Sync( m_syncer, m_options ) ;
UpdateChangeStamp( ) ;
} }
void Drive::DryRun() void Drive::DryRun()

View File

@ -44,7 +44,6 @@ public :
void Update() ; void Update() ;
void DryRun() ; void DryRun() ;
void SaveState() ; void SaveState() ;
void UpdateChangeStamp() ;
struct Error : virtual Exception {} ; struct Error : virtual Exception {} ;
@ -54,7 +53,8 @@ private :
void ReadChanges() ; void ReadChanges() ;
void FromRemote( const Entry& entry ) ; void FromRemote( const Entry& entry ) ;
void FromChange( const Entry& entry ) ; void FromChange( const Entry& entry ) ;
void UpdateChangeStamp( ) ;
private : private :
Syncer *m_syncer ; Syncer *m_syncer ;
fs::path m_root ; fs::path m_root ;

View File

@ -81,7 +81,8 @@ void State::FromLocal( const fs::path& p )
FromLocal( p, m_res.Root(), m_st.Item( "tree" ) ) ; FromLocal( p, m_res.Root(), m_st.Item( "tree" ) ) ;
} }
size_t State::getTotalChanges() { size_t State::getTotalChanges()
{
return m_res.Root()->size(); return m_res.Root()->size();
} }
@ -209,7 +210,6 @@ void State::FromChange( const Entry& e )
m_res.Update( res, e ) ; m_res.Update( res, e ) ;
} }
bool State::Update( const Entry& e ) bool State::Update( const Entry& e )
{ {
assert( !e.IsChange() ) ; assert( !e.IsChange() ) ;

View File

@ -65,13 +65,10 @@ void Entry2::Update( const Val& item )
m_is_editable = file["editable"].Bool() ; m_is_editable = file["editable"].Bool() ;
m_is_removed = file["labels"]["trashed"].Bool() ; m_is_removed = file["labels"]["trashed"].Bool() ;
if (file.Has("fileSize")) if ( file.Has( "fileSize" ) )
{ m_size = file["fileSize"].U64() ;
m_size = file["fileSize"].U64() ; else
} else m_size = 0;
{
m_size = 0;
}
if ( !m_is_dir ) if ( !m_is_dir )
{ {

View File

@ -140,8 +140,6 @@ std::string to_string( uint64_t n )
return s.str(); return s.str();
} }
bool Syncer2::Upload( Resource *res, bool new_rev ) bool Syncer2::Upload( Resource *res, bool new_rev )
{ {
Val meta; Val meta;

View File

@ -20,7 +20,6 @@
#include "Agent.hh" #include "Agent.hh"
#include "Header.hh" #include "Header.hh"
#include "util/StringStream.hh" #include "util/StringStream.hh"
#include <iostream>
namespace gr { namespace gr {
@ -38,7 +37,7 @@ long Agent::Put(
const Header& hdr ) const Header& hdr )
{ {
StringStream s( data ); StringStream s( data );
return Request( "PUT", url, &s, dest, hdr); return Request( "PUT", url, &s, dest, hdr );
} }
long Agent::Put( long Agent::Put(
@ -47,16 +46,16 @@ long Agent::Put(
DataStream *dest, DataStream *dest,
const Header& hdr ) const Header& hdr )
{ {
return Request( "PUT", url, (SeekStream*)file, dest, hdr); return Request( "PUT", url, (SeekStream*)file, dest, hdr );
} }
long Agent::Get( long Agent::Get(
const std::string& url, const std::string& url,
DataStream *dest, DataStream *dest,
const Header& hdr, const Header& hdr,
const long downloadFileBytes) const long downloadFileBytes )
{ {
return Request( "GET", url, NULL, dest, hdr, downloadFileBytes); return Request( "GET", url, NULL, dest, hdr, downloadFileBytes );
} }
long Agent::Post( long Agent::Post(
@ -68,7 +67,7 @@ long Agent::Post(
Header h( hdr ) ; Header h( hdr ) ;
StringStream s( data ); StringStream s( data );
h.Add( "Content-Type: application/x-www-form-urlencoded" ); h.Add( "Content-Type: application/x-www-form-urlencoded" );
return Request( "POST", url, &s, dest, h); return Request( "POST", url, &s, dest, h );
} }
void Agent::SetUploadSpeed( unsigned kbytes ) void Agent::SetUploadSpeed( unsigned kbytes )

View File

@ -61,7 +61,7 @@ public :
const std::string& url, const std::string& url,
DataStream *dest, DataStream *dest,
const Header& hdr, const Header& hdr,
const long downloadFileBytes = 0) ; const long downloadFileBytes = 0 ) ;
virtual long Post( virtual long Post(
const std::string& url, const std::string& url,
@ -75,7 +75,7 @@ public :
SeekStream *in, SeekStream *in,
DataStream *dest, DataStream *dest,
const Header& hdr, const Header& hdr,
const long downloadFileBytes = 0) = 0 ; const long downloadFileBytes = 0 ) = 0 ;
virtual void SetUploadSpeed( unsigned kbytes ) ; virtual void SetUploadSpeed( unsigned kbytes ) ;
virtual void SetDownloadSpeed( unsigned kbytes ) ; virtual void SetDownloadSpeed( unsigned kbytes ) ;

View File

@ -27,8 +27,6 @@
#include "util/File.hh" #include "util/File.hh"
#include <boost/throw_exception.hpp> #include <boost/throw_exception.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/lexical_cast.hpp>
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
@ -119,7 +117,7 @@ std::size_t CurlAgent::HeaderCallback( void *ptr, size_t size, size_t nmemb, Cur
{ {
char *str = static_cast<char*>(ptr) ; char *str = static_cast<char*>(ptr) ;
std::string line( str, str + size*nmemb ) ; std::string line( str, str + size*nmemb ) ;
// Check for error (HTTP 400 and above) // Check for error (HTTP 400 and above)
if ( line.substr( 0, 5 ) == "HTTP/" && line[9] >= '4' ) if ( line.substr( 0, 5 ) == "HTTP/" && line[9] >= '4' )
pthis->m_pimpl->error = true; pthis->m_pimpl->error = true;
@ -129,7 +127,7 @@ std::size_t CurlAgent::HeaderCallback( void *ptr, size_t size, size_t nmemb, Cur
if ( pthis->m_log.get() ) if ( pthis->m_log.get() )
pthis->m_log->Write( str, size*nmemb ); pthis->m_log->Write( str, size*nmemb );
static const std::string loc = "Location: " ; static const std::string loc = "Location: " ;
std::size_t pos = line.find( loc ) ; std::size_t pos = line.find( loc ) ;
if ( pos != line.npos ) if ( pos != line.npos )
@ -137,21 +135,20 @@ std::size_t CurlAgent::HeaderCallback( void *ptr, size_t size, size_t nmemb, Cur
std::size_t end_pos = line.find( "\r\n", pos ) ; std::size_t end_pos = line.find( "\r\n", pos ) ;
pthis->m_pimpl->location = line.substr( loc.size(), end_pos - loc.size() ) ; pthis->m_pimpl->location = line.substr( loc.size(), end_pos - loc.size() ) ;
} }
return size*nmemb ; return size*nmemb ;
} }
std::size_t CurlAgent::Receive( void* ptr, size_t size, size_t nmemb, CurlAgent *pthis ) std::size_t CurlAgent::Receive( void* ptr, size_t size, size_t nmemb, CurlAgent *pthis )
{ {
assert( pthis != 0 ) ; assert( pthis != 0 ) ;
if ( pthis->m_log.get() ) if ( pthis->m_log.get() )
pthis->m_log->Write( (const char*)ptr, size*nmemb ); pthis->m_log->Write( (const char*)ptr, size*nmemb );
if ( pthis->totalDownloadSize > 0 ) if ( pthis->totalDownloadSize > 0 )
{ {
pthis->downloadedBytes += (curl_off_t)size*nmemb; pthis->downloadedBytes += (curl_off_t)size*nmemb;
CurlAgent::progress_callback(pthis, pthis->totalDownloadSize, pthis->downloadedBytes, 0L, 0L); CurlAgent::progress_callback( pthis, pthis->totalDownloadSize, pthis->downloadedBytes, 0L, 0L );
} }
if ( pthis->m_pimpl->error && pthis->m_pimpl->error_data.size() < 65536 ) if ( pthis->m_pimpl->error && pthis->m_pimpl->error_data.size() < 65536 )
@ -163,14 +160,12 @@ std::size_t CurlAgent::Receive( void* ptr, size_t size, size_t nmemb, CurlAgent
return pthis->m_pimpl->dest->Write( static_cast<char*>(ptr), size * nmemb ) ; return pthis->m_pimpl->dest->Write( static_cast<char*>(ptr), size * nmemb ) ;
} }
int CurlAgent::progress_callback( void *ptr, curl_off_t totalDownloadSize, curl_off_t finishedDownloadSize, curl_off_t totalToUpload, curl_off_t finishedUploaded )
int CurlAgent::progress_callback(void *ptr, curl_off_t totalDownloadSize, curl_off_t finishedDownloadSize, curl_off_t totalToUpload, curl_off_t finishedUploaded)
{ {
((CurlAgent*)ptr)->m_pb->PrintProgressBar(totalDownloadSize, finishedDownloadSize, totalToUpload, finishedUploaded); ((CurlAgent*)ptr)->m_pb->PrintProgressBar(totalDownloadSize, finishedDownloadSize, totalToUpload, finishedUploaded);
return 0; return 0;
} }
long CurlAgent::ExecCurl( long CurlAgent::ExecCurl(
const std::string& url, const std::string& url,
DataStream *dest, DataStream *dest,
@ -227,9 +222,8 @@ long CurlAgent::Request(
SeekStream *in, SeekStream *in,
DataStream *dest, DataStream *dest,
const Header& hdr, const Header& hdr,
const long downloadFileBytes) const long downloadFileBytes )
{ {
Trace("HTTP %1% \"%2%\"", method, url ) ; Trace("HTTP %1% \"%2%\"", method, url ) ;
Init() ; Init() ;

View File

@ -46,7 +46,7 @@ public :
ResponseLog* GetLog() const ; ResponseLog* GetLog() const ;
void SetLog( ResponseLog *log ) ; void SetLog( ResponseLog *log ) ;
void SetProgressBar( ProgressBar *progressbar) ; void SetProgressBar( ProgressBar *progressbar ) ;
long Request( long Request(
const std::string& method, const std::string& method,
@ -54,7 +54,7 @@ public :
SeekStream *in, SeekStream *in,
DataStream *dest, DataStream *dest,
const Header& hdr, const Header& hdr,
const long downloadFileBytes = 0) ; const long downloadFileBytes = 0 ) ;
std::string LastError() const ; std::string LastError() const ;
std::string LastErrorHeaders() const ; std::string LastErrorHeaders() const ;
@ -64,7 +64,7 @@ public :
std::string Escape( const std::string& str ) ; std::string Escape( const std::string& str ) ;
std::string Unescape( const std::string& str ) ; std::string Unescape( const std::string& str ) ;
static int progress_callback(void *ptr, curl_off_t TotalDownloadSize, curl_off_t finishedDownloadSize, curl_off_t TotalToUpload, curl_off_t NowUploaded); static int progress_callback( void *ptr, curl_off_t TotalDownloadSize, curl_off_t finishedDownloadSize, curl_off_t TotalToUpload, curl_off_t NowUploaded );
private : private :
static std::size_t HeaderCallback( void *ptr, size_t size, size_t nmemb, CurlAgent *pthis ) ; static std::size_t HeaderCallback( void *ptr, size_t size, size_t nmemb, CurlAgent *pthis ) ;

View File

@ -77,7 +77,7 @@ long AuthAgent::Request(
SeekStream *in, SeekStream *in,
DataStream *dest, DataStream *dest,
const http::Header& hdr, const http::Header& hdr,
const long downloadFileBytes) const long downloadFileBytes )
{ {
long response; long response;
Header auth; Header auth;

View File

@ -45,7 +45,7 @@ public :
SeekStream *in, SeekStream *in,
DataStream *dest, DataStream *dest,
const http::Header& hdr, const http::Header& hdr,
const long downloadFileBytes = 0) ; const long downloadFileBytes = 0 ) ;
std::string LastError() const ; std::string LastError() const ;
std::string LastErrorHeaders() const ; std::string LastErrorHeaders() const ;