From 277274f02605417ad1283fb1ea6fffc8d9e59e90 Mon Sep 17 00:00:00 2001 From: Nestal Wan Date: Fri, 15 Jun 2012 00:55:00 +0800 Subject: [PATCH] fixed handling on changes feed. --- grive/src/main.cc | 9 +++++++-- libgrive/src/drive/Drive.cc | 25 +++++-------------------- libgrive/src/drive/Drive.hh | 1 - libgrive/src/drive/State.cc | 14 +++++++++++++- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/grive/src/main.cc b/grive/src/main.cc index 94c3d42..0844933 100644 --- a/grive/src/main.cc +++ b/grive/src/main.cc @@ -175,6 +175,7 @@ int Main( int argc, char **argv ) drive.SaveState() ; config.Save() ; + Log( "Finished!", log::info ) ; return 0 ; } @@ -187,10 +188,14 @@ int main( int argc, char **argv ) catch ( Exception& e ) { Log( "exception: %1%", boost::diagnostic_information(e), log::critical ) ; - return -1 ; + } + catch ( std::exception& e ) + { + Log( "exception: %1%", e.what(), log::critical ) ; } catch ( ... ) { - return -1 ; + Log( "unexpected exception", log::critical ) ; } + return -1 ; } diff --git a/libgrive/src/drive/Drive.cc b/libgrive/src/drive/Drive.cc index 68bff8a..081890b 100644 --- a/libgrive/src/drive/Drive.cc +++ b/libgrive/src/drive/Drive.cc @@ -66,6 +66,7 @@ Drive::Drive( OAuth2& auth, const Json& options ) : http::CurlAgent http ; long prev_stamp = m_state.ChangeStamp() ; + Trace( "previous time stamp is %1%", prev_stamp ) ; // get metadata http::XmlResponse xrsp ; @@ -89,7 +90,7 @@ Drive::Drive( OAuth2& auth, const Json& options ) : { std::for_each( feed.begin(), feed.end(), boost::bind( &Drive::FromRemote, this, _1 ) ) ; } while ( feed.GetNext( &http, m_http_hdr ) ) ; - + // pull the changes feed if ( prev_stamp != -1 ) { @@ -115,24 +116,6 @@ void Drive::FromRemote( const Entry& entry ) else if ( parent == 0 || !parent->IsInRootTree() ) Log( "file \"%1%\" parent doesn't exist, ignored", entry.Title(), log::verbose ) ; - else - FromEntry( entry ) ; -} - -void Drive::FromEntry( const Entry& entry ) -{ - std::string fn = entry.Filename() ; - - // common checkings - if ( fn.empty() || entry.ContentSrc().empty() ) - Log( "file \"%1%\" is a google document, ignored", entry.Title(), log::verbose ) ; - - else if ( fn.find('/') != fn.npos ) - Log( "file \"%1%\" contains a slash in its name, ignored", entry.Title(), log::verbose ) ; - - else if ( entry.ParentHrefs().size() != 1 ) - Log( "file \"%1%\" has multiple parents, ignored", entry.Title(), log::verbose ) ; - else m_state.FromRemote( entry ) ; } @@ -142,8 +125,10 @@ void Drive::FromChange( const Entry& entry ) if ( entry.IsRemoved() ) Log( "file \"%1%\" represents a deletion, ignored", entry.Title(), log::verbose ) ; + // folders go directly + else - FromEntry( entry ) ; + m_state.FromRemote( entry ) ; } void Drive::SaveState() diff --git a/libgrive/src/drive/Drive.hh b/libgrive/src/drive/Drive.hh index dd0c0bc..0b38e91 100644 --- a/libgrive/src/drive/Drive.hh +++ b/libgrive/src/drive/Drive.hh @@ -52,7 +52,6 @@ public : private : void SyncFolders( http::Agent *http ) ; void file(); - void FromEntry( const Entry& entry ) ; void FromRemote( const Entry& entry ) ; void FromChange( const Entry& entry ) ; diff --git a/libgrive/src/drive/State.cc b/libgrive/src/drive/State.cc index abaaf60..8dfcdce 100644 --- a/libgrive/src/drive/State.cc +++ b/libgrive/src/drive/State.cc @@ -103,12 +103,24 @@ void State::FromLocal( const fs::path& p, gr::Resource* folder ) void State::FromRemote( const Entry& e ) { + std::string fn = e.Filename() ; + if ( IsIgnore( e.Name() ) ) Log( "%1% %2% is ignored by grive", e.Kind(), e.Name(), log::verbose ) ; + // common checkings + else if ( e.Kind() != "folder" && (fn.empty() || e.ContentSrc().empty()) ) + Log( "%1% \"%2%\" is a google document, ignored", e.Kind(), e.Name(), log::verbose ) ; + + else if ( fn.find('/') != fn.npos ) + Log( "%1% \"%2%\" contains a slash in its name, ignored", e.Kind(), e.Name(), log::verbose ) ; + + else if ( !e.IsChange() && e.ParentHrefs().size() != 1 ) + Log( "%1% \"%2%\" has multiple parents, ignored", e.Kind(), e.Name(), log::verbose ) ; + else if ( e.IsChange() ) FromChange( e ) ; - + else if ( !Update( e ) ) { m_unresolved.push_back( e ) ;