From 991d8e444fe6635ddab335ba6e497cd03c4db582 Mon Sep 17 00:00:00 2001 From: Nestal Wan Date: Sun, 10 Jun 2012 23:38:27 +0800 Subject: [PATCH] recursively sync the resources --- libgrive/src/drive/Resource.cc | 21 ++++++++++++++------- libgrive/src/drive/Resource.hh | 1 + libgrive/src/drive/State.cc | 12 +----------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/libgrive/src/drive/Resource.cc b/libgrive/src/drive/Resource.cc index af40d51..823e0fb 100644 --- a/libgrive/src/drive/Resource.cc +++ b/libgrive/src/drive/Resource.cc @@ -37,6 +37,7 @@ #include "xml/NodeSet.hh" #include "xml/String.hh" +#include #include #include @@ -340,14 +341,16 @@ Resource* Resource::FindChild( const std::string& name ) void Resource::Sync( http::Agent *http, const http::Header& auth ) { assert( m_state != unknown ) ; - - // root folder is already synced - if ( IsRoot() ) - { - assert( m_state == sync ) ; - return ; - } + assert( !IsRoot() || m_state == sync ) ; // root folder is already synced + SyncSelf( http, auth ) ; + + std::for_each( m_child.begin(), m_child.end(), + boost::bind( &Resource::Sync, _1, http, auth ) ) ; +} + +void Resource::SyncSelf( http::Agent* http, const http::Header& auth ) +{ switch ( m_state ) { case local_new : @@ -393,6 +396,10 @@ void Resource::Sync( http::Agent *http, const http::Header& auth ) case sync : Log( "sync %1% already in sync", Path(), log::verbose ) ; break ; + + case unknown : + assert( false ) ; + break ; default : break ; diff --git a/libgrive/src/drive/Resource.hh b/libgrive/src/drive/Resource.hh index 7ab0094..ed1bf2e 100644 --- a/libgrive/src/drive/Resource.hh +++ b/libgrive/src/drive/Resource.hh @@ -134,6 +134,7 @@ private : void DeleteRemote( http::Agent* http, const http::Header& auth ) ; void AssignIDs( const Entry& remote ) ; + void SyncSelf( http::Agent* http, const http::Header& auth ) ; private : std::string m_name ; diff --git a/libgrive/src/drive/State.cc b/libgrive/src/drive/State.cc index 293c7af..abaaf60 100644 --- a/libgrive/src/drive/State.cc +++ b/libgrive/src/drive/State.cc @@ -29,14 +29,6 @@ #include "util/log/Log.hh" #include "protocol/Json.hh" -#include - -#include -#include -#include -#include -#include - #include namespace gr { @@ -260,9 +252,7 @@ void State::Write( const fs::path& filename ) const void State::Sync( http::Agent *http, const http::Header& auth ) { - std::for_each( m_res.begin(), m_res.end(), - boost::bind( &Resource::Sync, _1, http, auth ) ) ; - + m_res.Root()->Sync( http, auth ) ; m_last_sync = DateTime::Now() ; }