diff --git a/libgrive/src/drive/Resource.cc b/libgrive/src/drive/Resource.cc index eaa63b7..c1f459c 100644 --- a/libgrive/src/drive/Resource.cc +++ b/libgrive/src/drive/Resource.cc @@ -115,12 +115,34 @@ void Resource::FromRemoteFolder( const Entry& remote, const DateTime& last_sync /// one is newer. void Resource::FromRemote( const Entry& remote, const DateTime& last_sync ) { - fs::path path = Path() ; - // sync folder if ( remote.Kind() == "folder" && IsFolder() ) FromRemoteFolder( remote, last_sync ) ; + else + FromRemoteFile( remote, last_sync ) ; + m_entry.AssignID( remote ) ; + assert( m_state != unknown ) ; +} + +void Resource::FromRemoteFile( const Entry& remote, const DateTime& last_sync ) +{ + assert( m_parent != 0 ) ; + + fs::path path = Path() ; + + // recursively create/delete folder + if ( m_parent->m_state == remote_new || m_parent->m_state == remote_deleted || + m_parent->m_state == local_new || m_parent->m_state == local_deleted ) + { + Log( "file %1% parent %2% recursively in %3% (%4%)", path, + ( m_parent->m_state == remote_new || m_parent->m_state == local_new ) ? "created" : "deleted", + ( m_parent->m_state == remote_new || m_parent->m_state == remote_deleted ) ? "remode" : "local", + m_parent->m_state ) ; + + m_state = m_parent->m_state ; + } + // local not exists else if ( !fs::exists( path ) ) { @@ -164,9 +186,6 @@ void Resource::FromRemote( const Entry& remote, const DateTime& last_sync ) else Trace( "file 1% state is %2%", Name(), m_state ) ; } - - m_entry.AssignID( remote ) ; - assert( m_state != unknown ) ; } /// Update the resource with the attributes of local file or directory. This @@ -358,7 +377,7 @@ void Resource::DeleteRemote( http::Agent *http, const http::Headers& auth ) http::StringResponse str ; try { - http->Custom( "DELETE", m_entry.SelfHref(), &str, hdr ) ; + http->Custom( "DELETE", http->Unescape(m_entry.SelfHref()) , &str, hdr ) ; } catch ( Exception& ) { @@ -539,6 +558,11 @@ bool Resource::IsRoot() const return m_parent == 0 ; } +bool Resource::HasID() const +{ + return !m_entry.SelfHref().empty() && !m_entry.ResourceID().empty() ; +} + } // end of namespace namespace std diff --git a/libgrive/src/drive/Resource.hh b/libgrive/src/drive/Resource.hh index 5ba8ffd..1c3a4e4 100644 --- a/libgrive/src/drive/Resource.hh +++ b/libgrive/src/drive/Resource.hh @@ -67,6 +67,7 @@ public : fs::path Path() const ; bool IsInRootTree() const ; bool IsRoot() const ; + bool HasID() const ; void FromRemote( const Entry& remote, const DateTime& last_sync ) ; void FromLocal( const DateTime& last_sync ) ; @@ -122,7 +123,10 @@ private : bool EditContent( http::Agent* http, const http::Headers& auth ) ; bool Create( http::Agent* http, const http::Headers& auth ) ; bool Upload( http::Agent* http, const std::string& link, const http::Headers& auth, bool post ) ; + void FromRemoteFolder( const Entry& remote, const DateTime& last_sync ) ; + void FromRemoteFile( const Entry& remote, const DateTime& last_sync ) ; + void DeleteLocal() ; void DeleteRemote( http::Agent* http, const http::Headers& auth ) ; diff --git a/libgrive/src/drive/State.cc b/libgrive/src/drive/State.cc index 4ef578c..192b053 100644 --- a/libgrive/src/drive/State.cc +++ b/libgrive/src/drive/State.cc @@ -130,7 +130,7 @@ std::size_t State::TryResolveEntry() bool State::Update( const Entry& e ) { assert( !e.ParentHref().empty() ) ; - + if ( Resource *res = m_res.FindByHref( e.SelfHref() ) ) { m_res.Update( res, e, m_last_sync ) ; @@ -161,10 +161,6 @@ bool State::Update( const Entry& e ) // update the state of the resource m_res.Update( child, e, m_last_sync ) ; } - else - { - Trace( "what here? %1%", e.Title() ) ; - } return true ; } diff --git a/libgrive/src/util/Log.hh b/libgrive/src/util/Log.hh index 45360e0..35512c8 100644 --- a/libgrive/src/util/Log.hh +++ b/libgrive/src/util/Log.hh @@ -86,6 +86,18 @@ void Log( const std::string& fmt, const P1& p1, const P2& p2, const P3& p3, log: LogBase::Inst()->Log( log::Fmt(fmt) % p1 % p2 % p3, s ) ; } +template +void Log( + const std::string& fmt, + const P1& p1, + const P2& p2, + const P3& p3, + const P4& p4, + log::Serverity s = log::info ) +{ + LogBase::Inst()->Log( log::Fmt(fmt) % p1 % p2 % p3 % p4, s ) ; +} + void Trace( const std::string& str ) ; template