added more log for dry-run (#65)

pull/40/head
Nestal Wan 2012-06-17 16:33:38 +08:00
parent 55ac367255
commit 48391bb16f
6 changed files with 32 additions and 16 deletions

View File

@ -178,6 +178,8 @@ int Main( int argc, char **argv )
drive.Update() ; drive.Update() ;
drive.SaveState() ; drive.SaveState() ;
} }
else
drive.DryRun() ;
config.Save() ; config.Save() ;
Log( "Finished!", log::info ) ; Log( "Finished!", log::info ) ;

View File

@ -178,4 +178,10 @@ void Drive::Update()
m_state.Sync( &http, m_http_hdr ) ; 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 } // end of namespace

View File

@ -44,7 +44,7 @@ public :
Drive( OAuth2& auth, const Json& options ) ; Drive( OAuth2& auth, const Json& options ) ;
void Update() ; void Update() ;
void Sync() ; void DryRun() ;
void SaveState() ; void SaveState() ;
struct Error : virtual Exception {} ; struct Error : virtual Exception {} ;

View File

@ -370,41 +370,49 @@ void Resource::SyncSelf( http::Agent* http, const http::Header& auth )
case local_new : case local_new :
Log( "sync %1% doesn't exist in server, uploading", path, log::info ) ; 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 ; m_state = sync ;
break ; break ;
case local_deleted : case local_deleted :
Log( "sync %1% deleted in local. deleting remote", path, log::info ) ; Log( "sync %1% deleted in local. deleting remote", path, log::info ) ;
DeleteRemote( http, auth ) ; if ( http != 0 )
DeleteRemote( http, auth ) ;
break ; break ;
case local_changed : case local_changed :
Log( "sync %1% changed in local. uploading", path, log::info ) ; Log( "sync %1% changed in local. uploading", path, log::info ) ;
if ( EditContent( http, auth ) ) if ( http != 0 && EditContent( http, auth ) )
m_state = sync ; m_state = sync ;
break ; break ;
case remote_new : case remote_new :
Log( "sync %1% created in remote. creating local", path, log::info ) ; Log( "sync %1% created in remote. creating local", path, log::info ) ;
if ( IsFolder() ) if ( http != 0 )
fs::create_directories( path ) ; {
else if ( IsFolder() )
Download( http, path, auth ) ; fs::create_directories( path ) ;
else
m_state = sync ; Download( http, path, auth ) ;
m_state = sync ;
}
break ; break ;
case remote_changed : case remote_changed :
assert( !IsFolder() ) ; assert( !IsFolder() ) ;
Log( "sync %1% changed in remote. downloading", path, log::info ) ; Log( "sync %1% changed in remote. downloading", path, log::info ) ;
Download( http, path, auth ) ; if ( http != 0 )
m_state = sync ; {
Download( http, path, auth ) ;
m_state = sync ;
}
break ; break ;
case remote_deleted : case remote_deleted :
Log( "sync %1% deleted in remote. deleting local", path, log::info ) ; Log( "sync %1% deleted in remote. deleting local", path, log::info ) ;
DeleteLocal() ; if ( http != 0 )
DeleteLocal() ;
break ; break ;
case sync : case sync :
@ -446,6 +454,7 @@ void Resource::DeleteLocal()
void Resource::DeleteRemote( http::Agent *http, const http::Header& auth ) void Resource::DeleteRemote( http::Agent *http, const http::Header& auth )
{ {
assert( http != 0 ) ;
http::StringResponse str ; http::StringResponse str ;
try try

View File

@ -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 ) for ( fs::directory_iterator i( p ) ; i != fs::directory_iterator() ; ++i )
{ {
std::string fname = Path2Str(i->path().filename()) ; std::string fname = Path2Str(i->path().filename()) ;
// Trace( "found file %1%", i->path() ) ;
if ( IsIgnore(fname) ) if ( IsIgnore(fname) )
Log( "file %1% is ignored by grive", fname, log::verbose ) ; Log( "file %1% is ignored by grive", fname, log::verbose ) ;

View File

@ -23,14 +23,12 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector>
namespace gr { namespace http { namespace gr { namespace http {
class Receivable ; class Receivable ;
/*! \class Agent /*! \brief agent to provide HTTP access
\brief class to provide HTTP access
This class provides functions to send HTTP request in many methods (e.g. get, post and put). 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. Normally the HTTP response is returned in a Receivable.