diff --git a/grive/src/main.cc b/grive/src/main.cc index a0f5c25..644064b 100644 --- a/grive/src/main.cc +++ b/grive/src/main.cc @@ -45,7 +45,6 @@ #include #include - const std::string client_id = "22314510474.apps.googleusercontent.com" ; const std::string client_secret = "bl4ufi89h-9MkFlypcI7R785" ; @@ -151,7 +150,7 @@ int Main( int argc, char **argv ) InitLog(vm) ; Config config(vm) ; - + Log( "config file name %1%", config.Filename(), log::verbose ); std::unique_ptr http( new http::CurlAgent ); @@ -183,7 +182,6 @@ int Main( int argc, char **argv ) config.Set( "refresh_token", Val( token.RefreshToken() ) ) ; config.Save() ; } - std::string refresh_token ; try @@ -216,17 +214,16 @@ int Main( int argc, char **argv ) if ( vm.count( "dry-run" ) == 0 ) { - //The progress bar should just be enabled when actual file transfers take place - pb->SetShowProgressBar(true); + // The progress bar should just be enabled when actual file transfers take place + pb->SetShowProgressBar( true ) ; drive.Update() ; - pb->SetShowProgressBar(false); + pb->SetShowProgressBar( false ) ; - drive.UpdateChangeStamp(); drive.SaveState() ; } else drive.DryRun() ; - + config.Save() ; Log( "Finished!", log::info ) ; return 0 ; diff --git a/libgrive/src/base/Drive.cc b/libgrive/src/base/Drive.cc index c05d053..9686b9b 100644 --- a/libgrive/src/base/Drive.cc +++ b/libgrive/src/base/Drive.cc @@ -92,8 +92,8 @@ void Drive::DetectChanges() m_state.ResolveEntry() ; } - -size_t Drive::getTotalChanges() { +size_t Drive::getTotalChanges() +{ return m_state.getTotalChanges(); } @@ -120,6 +120,8 @@ void Drive::Update() { Log( "Synchronizing files", log::info ) ; m_state.Sync( m_syncer, m_options ) ; + + UpdateChangeStamp( ) ; } void Drive::DryRun() diff --git a/libgrive/src/base/Drive.hh b/libgrive/src/base/Drive.hh index c534e4f..cb86c98 100644 --- a/libgrive/src/base/Drive.hh +++ b/libgrive/src/base/Drive.hh @@ -44,7 +44,6 @@ public : void Update() ; void DryRun() ; void SaveState() ; - void UpdateChangeStamp() ; struct Error : virtual Exception {} ; @@ -54,7 +53,8 @@ private : void ReadChanges() ; void FromRemote( const Entry& entry ) ; void FromChange( const Entry& entry ) ; - + void UpdateChangeStamp( ) ; + private : Syncer *m_syncer ; fs::path m_root ; diff --git a/libgrive/src/base/State.cc b/libgrive/src/base/State.cc index 41ce2aa..a290416 100644 --- a/libgrive/src/base/State.cc +++ b/libgrive/src/base/State.cc @@ -81,7 +81,8 @@ void State::FromLocal( const fs::path& p ) FromLocal( p, m_res.Root(), m_st.Item( "tree" ) ) ; } -size_t State::getTotalChanges() { +size_t State::getTotalChanges() +{ return m_res.Root()->size(); } @@ -209,7 +210,6 @@ void State::FromChange( const Entry& e ) m_res.Update( res, e ) ; } - bool State::Update( const Entry& e ) { assert( !e.IsChange() ) ; diff --git a/libgrive/src/drive2/Entry2.cc b/libgrive/src/drive2/Entry2.cc index 09eeecb..9566029 100644 --- a/libgrive/src/drive2/Entry2.cc +++ b/libgrive/src/drive2/Entry2.cc @@ -65,13 +65,10 @@ void Entry2::Update( const Val& item ) m_is_editable = file["editable"].Bool() ; m_is_removed = file["labels"]["trashed"].Bool() ; - if (file.Has("fileSize")) - { - m_size = file["fileSize"].U64() ; - } else - { - m_size = 0; - } + if ( file.Has( "fileSize" ) ) + m_size = file["fileSize"].U64() ; + else + m_size = 0; if ( !m_is_dir ) { diff --git a/libgrive/src/drive2/Syncer2.cc b/libgrive/src/drive2/Syncer2.cc index 1b993c4..fa5e05d 100644 --- a/libgrive/src/drive2/Syncer2.cc +++ b/libgrive/src/drive2/Syncer2.cc @@ -140,8 +140,6 @@ std::string to_string( uint64_t n ) return s.str(); } - - bool Syncer2::Upload( Resource *res, bool new_rev ) { Val meta; diff --git a/libgrive/src/http/Agent.cc b/libgrive/src/http/Agent.cc index e63fa27..2f5a6ad 100644 --- a/libgrive/src/http/Agent.cc +++ b/libgrive/src/http/Agent.cc @@ -20,7 +20,6 @@ #include "Agent.hh" #include "Header.hh" #include "util/StringStream.hh" -#include namespace gr { @@ -38,7 +37,7 @@ long Agent::Put( const Header& hdr ) { StringStream s( data ); - return Request( "PUT", url, &s, dest, hdr); + return Request( "PUT", url, &s, dest, hdr ); } long Agent::Put( @@ -47,16 +46,16 @@ long Agent::Put( DataStream *dest, const Header& hdr ) { - return Request( "PUT", url, (SeekStream*)file, dest, hdr); + return Request( "PUT", url, (SeekStream*)file, dest, hdr ); } long Agent::Get( const std::string& url, DataStream *dest, 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( @@ -68,7 +67,7 @@ long Agent::Post( Header h( hdr ) ; StringStream s( data ); 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 ) diff --git a/libgrive/src/http/Agent.hh b/libgrive/src/http/Agent.hh index a1c8be8..8fb38fa 100644 --- a/libgrive/src/http/Agent.hh +++ b/libgrive/src/http/Agent.hh @@ -61,7 +61,7 @@ public : const std::string& url, DataStream *dest, const Header& hdr, - const long downloadFileBytes = 0) ; + const long downloadFileBytes = 0 ) ; virtual long Post( const std::string& url, @@ -75,7 +75,7 @@ public : SeekStream *in, DataStream *dest, const Header& hdr, - const long downloadFileBytes = 0) = 0 ; + const long downloadFileBytes = 0 ) = 0 ; virtual void SetUploadSpeed( unsigned kbytes ) ; virtual void SetDownloadSpeed( unsigned kbytes ) ; diff --git a/libgrive/src/http/CurlAgent.cc b/libgrive/src/http/CurlAgent.cc index 3ff62a6..f205aa9 100644 --- a/libgrive/src/http/CurlAgent.cc +++ b/libgrive/src/http/CurlAgent.cc @@ -27,8 +27,6 @@ #include "util/File.hh" #include -#include -#include #include #include @@ -119,7 +117,7 @@ std::size_t CurlAgent::HeaderCallback( void *ptr, size_t size, size_t nmemb, Cur { char *str = static_cast(ptr) ; std::string line( str, str + size*nmemb ) ; - + // Check for error (HTTP 400 and above) if ( line.substr( 0, 5 ) == "HTTP/" && line[9] >= '4' ) 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() ) pthis->m_log->Write( str, size*nmemb ); - + static const std::string loc = "Location: " ; std::size_t pos = line.find( loc ) ; 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 ) ; pthis->m_pimpl->location = line.substr( loc.size(), end_pos - loc.size() ) ; } - + return size*nmemb ; } std::size_t CurlAgent::Receive( void* ptr, size_t size, size_t nmemb, CurlAgent *pthis ) { assert( pthis != 0 ) ; - if ( pthis->m_log.get() ) pthis->m_log->Write( (const char*)ptr, size*nmemb ); if ( pthis->totalDownloadSize > 0 ) { 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 ) @@ -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(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); return 0; } - long CurlAgent::ExecCurl( const std::string& url, DataStream *dest, @@ -227,9 +222,8 @@ long CurlAgent::Request( SeekStream *in, DataStream *dest, const Header& hdr, - const long downloadFileBytes) + const long downloadFileBytes ) { - Trace("HTTP %1% \"%2%\"", method, url ) ; Init() ; diff --git a/libgrive/src/http/CurlAgent.hh b/libgrive/src/http/CurlAgent.hh index c221a0e..4ce6581 100644 --- a/libgrive/src/http/CurlAgent.hh +++ b/libgrive/src/http/CurlAgent.hh @@ -46,7 +46,7 @@ public : ResponseLog* GetLog() const ; void SetLog( ResponseLog *log ) ; - void SetProgressBar( ProgressBar *progressbar) ; + void SetProgressBar( ProgressBar *progressbar ) ; long Request( const std::string& method, @@ -54,7 +54,7 @@ public : SeekStream *in, DataStream *dest, const Header& hdr, - const long downloadFileBytes = 0) ; + const long downloadFileBytes = 0 ) ; std::string LastError() const ; std::string LastErrorHeaders() const ; @@ -64,7 +64,7 @@ public : std::string Escape( 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 : static std::size_t HeaderCallback( void *ptr, size_t size, size_t nmemb, CurlAgent *pthis ) ; diff --git a/libgrive/src/protocol/AuthAgent.cc b/libgrive/src/protocol/AuthAgent.cc index ea8bca9..06ee49e 100644 --- a/libgrive/src/protocol/AuthAgent.cc +++ b/libgrive/src/protocol/AuthAgent.cc @@ -77,7 +77,7 @@ long AuthAgent::Request( SeekStream *in, DataStream *dest, const http::Header& hdr, - const long downloadFileBytes) + const long downloadFileBytes ) { long response; Header auth; diff --git a/libgrive/src/protocol/AuthAgent.hh b/libgrive/src/protocol/AuthAgent.hh index 2829cc8..45e28a8 100644 --- a/libgrive/src/protocol/AuthAgent.hh +++ b/libgrive/src/protocol/AuthAgent.hh @@ -45,7 +45,7 @@ public : SeekStream *in, DataStream *dest, const http::Header& hdr, - const long downloadFileBytes = 0) ; + const long downloadFileBytes = 0 ) ; std::string LastError() const ; std::string LastErrorHeaders() const ;