fixed handling on changes feed.

pull/40/head
Nestal Wan 2012-06-15 00:55:00 +08:00
parent dbf0ae4be0
commit 277274f026
4 changed files with 25 additions and 24 deletions

View File

@ -175,6 +175,7 @@ int Main( int argc, char **argv )
drive.SaveState() ; drive.SaveState() ;
config.Save() ; config.Save() ;
Log( "Finished!", log::info ) ;
return 0 ; return 0 ;
} }
@ -187,10 +188,14 @@ int main( int argc, char **argv )
catch ( Exception& e ) catch ( Exception& e )
{ {
Log( "exception: %1%", boost::diagnostic_information(e), log::critical ) ; Log( "exception: %1%", boost::diagnostic_information(e), log::critical ) ;
return -1 ; }
catch ( std::exception& e )
{
Log( "exception: %1%", e.what(), log::critical ) ;
} }
catch ( ... ) catch ( ... )
{ {
return -1 ; Log( "unexpected exception", log::critical ) ;
} }
return -1 ;
} }

View File

@ -66,6 +66,7 @@ Drive::Drive( OAuth2& auth, const Json& options ) :
http::CurlAgent http ; http::CurlAgent http ;
long prev_stamp = m_state.ChangeStamp() ; long prev_stamp = m_state.ChangeStamp() ;
Trace( "previous time stamp is %1%", prev_stamp ) ;
// get metadata // get metadata
http::XmlResponse xrsp ; 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 ) ) ; std::for_each( feed.begin(), feed.end(), boost::bind( &Drive::FromRemote, this, _1 ) ) ;
} while ( feed.GetNext( &http, m_http_hdr ) ) ; } while ( feed.GetNext( &http, m_http_hdr ) ) ;
// pull the changes feed // pull the changes feed
if ( prev_stamp != -1 ) if ( prev_stamp != -1 )
{ {
@ -115,24 +116,6 @@ void Drive::FromRemote( const Entry& entry )
else if ( parent == 0 || !parent->IsInRootTree() ) else if ( parent == 0 || !parent->IsInRootTree() )
Log( "file \"%1%\" parent doesn't exist, ignored", entry.Title(), log::verbose ) ; 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 else
m_state.FromRemote( entry ) ; m_state.FromRemote( entry ) ;
} }
@ -142,8 +125,10 @@ void Drive::FromChange( const Entry& entry )
if ( entry.IsRemoved() ) if ( entry.IsRemoved() )
Log( "file \"%1%\" represents a deletion, ignored", entry.Title(), log::verbose ) ; Log( "file \"%1%\" represents a deletion, ignored", entry.Title(), log::verbose ) ;
// folders go directly
else else
FromEntry( entry ) ; m_state.FromRemote( entry ) ;
} }
void Drive::SaveState() void Drive::SaveState()

View File

@ -52,7 +52,6 @@ public :
private : private :
void SyncFolders( http::Agent *http ) ; void SyncFolders( http::Agent *http ) ;
void file(); void file();
void FromEntry( const Entry& entry ) ;
void FromRemote( const Entry& entry ) ; void FromRemote( const Entry& entry ) ;
void FromChange( const Entry& entry ) ; void FromChange( const Entry& entry ) ;

View File

@ -103,12 +103,24 @@ void State::FromLocal( const fs::path& p, gr::Resource* folder )
void State::FromRemote( const Entry& e ) void State::FromRemote( const Entry& e )
{ {
std::string fn = e.Filename() ;
if ( IsIgnore( e.Name() ) ) if ( IsIgnore( e.Name() ) )
Log( "%1% %2% is ignored by grive", e.Kind(), e.Name(), log::verbose ) ; 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() ) else if ( e.IsChange() )
FromChange( e ) ; FromChange( e ) ;
else if ( !Update( e ) ) else if ( !Update( e ) )
{ {
m_unresolved.push_back( e ) ; m_unresolved.push_back( e ) ;