From 48391bb16f4018f1d7c7faf80fcd9ca30f2a1397 Mon Sep 17 00:00:00 2001 From: Nestal Wan Date: Sun, 17 Jun 2012 16:33:38 +0800 Subject: [PATCH] added more log for dry-run (#65) --- grive/src/main.cc | 2 ++ libgrive/src/drive/Drive.cc | 6 ++++++ libgrive/src/drive/Drive.hh | 2 +- libgrive/src/drive/Resource.cc | 33 +++++++++++++++++++++------------ libgrive/src/drive/State.cc | 1 + libgrive/src/http/CurlAgent.hh | 4 +--- 6 files changed, 32 insertions(+), 16 deletions(-) diff --git a/grive/src/main.cc b/grive/src/main.cc index 3c968af..e38b0f6 100644 --- a/grive/src/main.cc +++ b/grive/src/main.cc @@ -178,6 +178,8 @@ int Main( int argc, char **argv ) drive.Update() ; drive.SaveState() ; } + else + drive.DryRun() ; config.Save() ; Log( "Finished!", log::info ) ; diff --git a/libgrive/src/drive/Drive.cc b/libgrive/src/drive/Drive.cc index 081890b..5fd43f8 100644 --- a/libgrive/src/drive/Drive.cc +++ b/libgrive/src/drive/Drive.cc @@ -178,4 +178,10 @@ void Drive::Update() m_state.Sync( &http, m_http_hdr ) ; } +void Drive::DryRun() +{ + Log( "Synchronizing files (dry-run)", log::info ) ; + m_state.Sync( 0, m_http_hdr ) ; +} + } // end of namespace diff --git a/libgrive/src/drive/Drive.hh b/libgrive/src/drive/Drive.hh index 0b38e91..2a51c60 100644 --- a/libgrive/src/drive/Drive.hh +++ b/libgrive/src/drive/Drive.hh @@ -44,7 +44,7 @@ public : Drive( OAuth2& auth, const Json& options ) ; void Update() ; - void Sync() ; + void DryRun() ; void SaveState() ; struct Error : virtual Exception {} ; diff --git a/libgrive/src/drive/Resource.cc b/libgrive/src/drive/Resource.cc index f29bd72..263157c 100644 --- a/libgrive/src/drive/Resource.cc +++ b/libgrive/src/drive/Resource.cc @@ -370,41 +370,49 @@ void Resource::SyncSelf( http::Agent* http, const http::Header& auth ) case local_new : Log( "sync %1% doesn't exist in server, uploading", path, log::info ) ; - if ( Create( http, auth ) ) + if ( http != 0 && Create( http, auth ) ) m_state = sync ; break ; case local_deleted : Log( "sync %1% deleted in local. deleting remote", path, log::info ) ; - DeleteRemote( http, auth ) ; + if ( http != 0 ) + DeleteRemote( http, auth ) ; break ; case local_changed : Log( "sync %1% changed in local. uploading", path, log::info ) ; - if ( EditContent( http, auth ) ) + if ( http != 0 && EditContent( http, auth ) ) m_state = sync ; break ; case remote_new : Log( "sync %1% created in remote. creating local", path, log::info ) ; - if ( IsFolder() ) - fs::create_directories( path ) ; - else - Download( http, path, auth ) ; - - m_state = sync ; + if ( http != 0 ) + { + if ( IsFolder() ) + fs::create_directories( path ) ; + else + Download( http, path, auth ) ; + + m_state = sync ; + } break ; case remote_changed : assert( !IsFolder() ) ; Log( "sync %1% changed in remote. downloading", path, log::info ) ; - Download( http, path, auth ) ; - m_state = sync ; + if ( http != 0 ) + { + Download( http, path, auth ) ; + m_state = sync ; + } break ; case remote_deleted : Log( "sync %1% deleted in remote. deleting local", path, log::info ) ; - DeleteLocal() ; + if ( http != 0 ) + DeleteLocal() ; break ; case sync : @@ -446,6 +454,7 @@ void Resource::DeleteLocal() void Resource::DeleteRemote( http::Agent *http, const http::Header& auth ) { + assert( http != 0 ) ; http::StringResponse str ; try diff --git a/libgrive/src/drive/State.cc b/libgrive/src/drive/State.cc index 8dfcdce..17aab2e 100644 --- a/libgrive/src/drive/State.cc +++ b/libgrive/src/drive/State.cc @@ -73,6 +73,7 @@ void State::FromLocal( const fs::path& p, gr::Resource* folder ) for ( fs::directory_iterator i( p ) ; i != fs::directory_iterator() ; ++i ) { std::string fname = Path2Str(i->path().filename()) ; +// Trace( "found file %1%", i->path() ) ; if ( IsIgnore(fname) ) Log( "file %1% is ignored by grive", fname, log::verbose ) ; diff --git a/libgrive/src/http/CurlAgent.hh b/libgrive/src/http/CurlAgent.hh index 2d0681f..b175638 100644 --- a/libgrive/src/http/CurlAgent.hh +++ b/libgrive/src/http/CurlAgent.hh @@ -23,14 +23,12 @@ #include #include -#include namespace gr { namespace http { class Receivable ; -/*! \class Agent - \brief class to provide HTTP access +/*! \brief agent to provide HTTP access This class provides functions to send HTTP request in many methods (e.g. get, post and put). Normally the HTTP response is returned in a Receivable.