Skip to content

Commit

Permalink
added more log for dry-run (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
nestal committed Jun 17, 2012
1 parent 55ac367 commit 48391bb
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
2 changes: 2 additions & 0 deletions grive/src/main.cc
Expand Up @@ -178,6 +178,8 @@ int Main( int argc, char **argv )
drive.Update() ;
drive.SaveState() ;
}
else
drive.DryRun() ;

config.Save() ;
Log( "Finished!", log::info ) ;
Expand Down
6 changes: 6 additions & 0 deletions libgrive/src/drive/Drive.cc
Expand Up @@ -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
2 changes: 1 addition & 1 deletion libgrive/src/drive/Drive.hh
Expand Up @@ -44,7 +44,7 @@ public :
Drive( OAuth2& auth, const Json& options ) ;

void Update() ;
void Sync() ;
void DryRun() ;
void SaveState() ;

struct Error : virtual Exception {} ;
Expand Down
33 changes: 21 additions & 12 deletions libgrive/src/drive/Resource.cc
Expand Up @@ -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 :
Expand Down Expand Up @@ -446,6 +454,7 @@ void Resource::DeleteLocal()

void Resource::DeleteRemote( http::Agent *http, const http::Header& auth )
{
assert( http != 0 ) ;
http::StringResponse str ;

try
Expand Down
1 change: 1 addition & 0 deletions libgrive/src/drive/State.cc
Expand Up @@ -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 ) ;
Expand Down
4 changes: 1 addition & 3 deletions libgrive/src/http/CurlAgent.hh
Expand Up @@ -23,14 +23,12 @@

#include <memory>
#include <string>
#include <vector>

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.
Expand Down

0 comments on commit 48391bb

Please sign in to comment.