From 3dd3f544fbbd2634e6fc5841f151b5531b6291d0 Mon Sep 17 00:00:00 2001 From: Matchman Green Date: Sun, 20 May 2012 15:25:38 +0800 Subject: [PATCH] minor clean up --- libgrive/src/drive/State.cc | 68 ++++++++++++++++--------------------- libgrive/src/drive/State.hh | 6 ++-- libgrive/src/xml/Node.cc | 4 ++- 3 files changed, 34 insertions(+), 44 deletions(-) diff --git a/libgrive/src/drive/State.cc b/libgrive/src/drive/State.cc index 2927305..7b7e0f4 100644 --- a/libgrive/src/drive/State.cc +++ b/libgrive/src/drive/State.cc @@ -44,11 +44,6 @@ State::State( const fs::path& filename ) Read( filename ); } -void State::Read( const fs::path& filename ) -{ - Trace( "reading %1%", filename ) ; -} - std::string State::ChangeStamp() const { return m_change_stamp ; @@ -63,7 +58,7 @@ void State::ChangeStamp( const std::string& cs ) /// of local directory. void State::FromLocal( const fs::path& p ) { - FromLocal( p, m_folders.Root() ) ; + FromLocal( p, m_res.Root() ) ; } void State::FromLocal( const fs::path& p, gr::Resource* folder ) @@ -73,38 +68,21 @@ void State::FromLocal( const fs::path& p, gr::Resource* folder ) for ( fs::directory_iterator i( p ) ; i != fs::directory_iterator() ; ++i ) { - if ( fs::is_directory( i->path() ) ) - { - Resource *c = new Resource( i->path() ) ; - folder->AddChild( c ) ; - m_folders.Insert( c ) ; - - FromLocal( *i, c ) ; - } - else if ( i->path().filename().string()[0] == '.' ) + if ( i->path().filename().string()[0] == '.' ) Log( "file %1% is ignored by grive", i->path().filename().string(), log::info ) ; + else { Resource *c = new Resource( i->path() ) ; folder->AddChild( c ) ; - m_folders.Insert( c ) ; + m_res.Insert( c ) ; + + if ( fs::is_directory( i->path() ) ) + FromLocal( *i, c ) ; } } } -void State::Write( const fs::path& filename ) const -{ - Json result ; - result.Add( "change_stamp", Json( m_change_stamp ) ) ; - - std::ofstream fs( filename.string().c_str() ) ; - fs << result ; -} - -void State::SetId( const fs::path& p, const std::string& id ) -{ -} - void State::FromRemote( const Entry& e ) { if ( !Update( e ) ) @@ -146,22 +124,20 @@ bool State::Update( const Entry& e ) { assert( !e.ParentHref().empty() ) ; - Resource *parent = m_folders.FindByHref( e.ParentHref() ) ; +// Resource *r = m_res.FindByID( e.ResourceID() ) ; + + Resource *parent = m_res.FindByHref( e.ParentHref() ) ; if ( parent != 0 ) { assert( parent->IsFolder() ) ; -Trace( "remote entry title %1%, filename %2%", e.Title(), e.Filename() ) ; // see if the entry already exist in local std::string name = ( e.Kind() == "folder" ? e.Title() : e.Filename() ) ; Resource *child = parent->FindChild( name ) ; if ( child != 0 ) { -// Trace( "remote entry %1%, local %2%", e.Title(), child->Name() ) ; -// assert( child == m_folders.FindByHref( e.SelfHref() ) ) ; - // since we are updating the ID and Href, we need to remove it and re-add it. - m_folders.Update( child, e ) ; + m_res.Update( child, e ) ; } // folder entry exist in google drive, but not local. we should create @@ -170,7 +146,7 @@ Trace( "remote entry title %1%, filename %2%", e.Title(), e.Filename() ) ; { child = new Resource( e ) ; parent->AddChild( child ) ; - m_folders.Insert( child ) ; + m_res.Insert( child ) ; fs::path child_path = child->Path() ; if ( child->IsFolder() && !fs::is_directory( child_path ) ) @@ -192,17 +168,31 @@ Trace( "remote entry title %1%, filename %2%", e.Title(), e.Filename() ) ; Resource* State::FindFolderByHref( const std::string& href ) { - return m_folders.FindByHref( href ) ; + return m_res.FindByHref( href ) ; } State::iterator State::begin() { - return m_folders.begin() ; + return m_res.begin() ; } State::iterator State::end() { - return m_folders.end() ; + return m_res.end() ; +} + +void State::Read( const fs::path& filename ) +{ + Trace( "reading %1%", filename ) ; +} + +void State::Write( const fs::path& filename ) const +{ + Json result ; + result.Add( "change_stamp", Json( m_change_stamp ) ) ; + + std::ofstream fs( filename.string().c_str() ) ; + fs << result ; } } // end of namespace diff --git a/libgrive/src/drive/State.hh b/libgrive/src/drive/State.hh index 8eeb53e..f211ca2 100644 --- a/libgrive/src/drive/State.hh +++ b/libgrive/src/drive/State.hh @@ -42,8 +42,6 @@ public : void FromRemote( const Entry& e ) ; void ResolveEntry() ; - void SetId( const fs::path& p, const std::string& id ) ; - void Read( const fs::path& filename ) ; void Write( const fs::path& filename ) const ; @@ -62,8 +60,8 @@ private : std::size_t TryResolveEntry() ; private : - ResourceTree m_folders ; - std::string m_change_stamp ; + ResourceTree m_res ; ; + std::string m_change_stamp ; std::vector m_unresolved ; } ; diff --git a/libgrive/src/xml/Node.cc b/libgrive/src/xml/Node.cc index 7ba0947..c8c71f3 100644 --- a/libgrive/src/xml/Node.cc +++ b/libgrive/src/xml/Node.cc @@ -196,8 +196,10 @@ private : ImplVec m_children ; } ; -Node::iterator::iterator( ImplVec::iterator i )// : iterator_adaptor(i) +Node::iterator::iterator( ImplVec::iterator i ) { + // for some reason, gcc 4.4.4 doesn't allow me to initialize the base class + // in the initializer. I have no choice but to initialize here. base_reference() = i ; }