mirror of https://github.com/vitalif/grive2
added more test cases and some minor refactoring
parent
050c89c3d8
commit
61c01019f7
|
@ -93,22 +93,22 @@ Drive::Drive( OAuth2& auth ) :
|
||||||
if ( (*i)["content"] == "" )
|
if ( (*i)["content"] == "" )
|
||||||
continue ;
|
continue ;
|
||||||
|
|
||||||
Entry file( *i ) ;
|
Entry entry( *i ) ;
|
||||||
if ( file.Kind() != "folder" )
|
if ( entry.Kind() != "folder" )
|
||||||
{
|
{
|
||||||
Resource *p = m_state.FindFolderByHref( file.ParentHref() ) ;
|
Resource *parent = m_state.FindByHref( entry.ParentHref() ) ;
|
||||||
if ( file.Filename().empty() )
|
if ( entry.Filename().empty() )
|
||||||
Log( "file \"%1%\" is a google document, ignored", file.Title(), log::info ) ;
|
Log( "file \"%1%\" is a google document, ignored", entry.Title(), log::info ) ;
|
||||||
|
|
||||||
else if ( file.ParentHref().empty() || p == 0 || !p->IsInRootTree() )
|
else if ( parent == 0 || !parent->IsInRootTree() )
|
||||||
Log( "file \"%1%\" parent doesn't exist, ignored", file.Title(), log::info ) ;
|
Log( "file \"%1%\" parent doesn't exist, ignored", entry.Title(), log::info ) ;
|
||||||
|
|
||||||
else if ( p != 0 && !p->IsFolder() )
|
else if ( parent != 0 && !parent->IsFolder() )
|
||||||
Log( "entry %1% has parent %2% which is not a folder, ignored",
|
Log( "entry %1% has parent %2% which is not a folder, ignored",
|
||||||
file.Title(), p->Name(), log::info ) ;
|
entry.Title(), parent->Name(), log::info ) ;
|
||||||
|
|
||||||
else
|
else
|
||||||
m_state.FromRemote( file ) ;
|
m_state.FromRemote( entry ) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ public :
|
||||||
|
|
||||||
private :
|
private :
|
||||||
void ConstructDirTree( http::Agent *http ) ;
|
void ConstructDirTree( http::Agent *http ) ;
|
||||||
|
void file();
|
||||||
|
|
||||||
private :
|
private :
|
||||||
OAuth2& m_auth ;
|
OAuth2& m_auth ;
|
||||||
|
|
|
@ -154,11 +154,13 @@ std::string Resource::ResourceID() const
|
||||||
|
|
||||||
const Resource* Resource::Parent() const
|
const Resource* Resource::Parent() const
|
||||||
{
|
{
|
||||||
|
assert( m_parent == 0 || m_parent->IsFolder() ) ;
|
||||||
return m_parent ;
|
return m_parent ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Resource* Resource::Parent()
|
Resource* Resource::Parent()
|
||||||
{
|
{
|
||||||
|
assert( m_parent == 0 || m_parent->IsFolder() ) ;
|
||||||
return m_parent ;
|
return m_parent ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,6 +184,7 @@ void Resource::Swap( Resource& coll )
|
||||||
m_entry.Swap( coll.m_entry ) ;
|
m_entry.Swap( coll.m_entry ) ;
|
||||||
std::swap( m_parent, coll.m_parent ) ;
|
std::swap( m_parent, coll.m_parent ) ;
|
||||||
m_child.swap( coll.m_child ) ;
|
m_child.swap( coll.m_child ) ;
|
||||||
|
std::swap( m_state, coll.m_state ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Resource::IsFolder() const
|
bool Resource::IsFolder() const
|
||||||
|
@ -395,6 +398,13 @@ std::ostream& operator<<( std::ostream& os, Resource::State s )
|
||||||
return os << state[s] ;
|
return os << state[s] ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Resource::StateStr() const
|
||||||
|
{
|
||||||
|
std::ostringstream ss ;
|
||||||
|
ss << m_state ;
|
||||||
|
return ss.str() ;
|
||||||
|
}
|
||||||
|
|
||||||
} // end of namespace
|
} // end of namespace
|
||||||
|
|
||||||
namespace std
|
namespace std
|
||||||
|
|
|
@ -83,6 +83,8 @@ public :
|
||||||
iterator end() const ;
|
iterator end() const ;
|
||||||
std::size_t size() const ;
|
std::size_t size() const ;
|
||||||
|
|
||||||
|
std::string StateStr() const ;
|
||||||
|
|
||||||
private :
|
private :
|
||||||
/// State of the resource. indicating what to do with the resource
|
/// State of the resource. indicating what to do with the resource
|
||||||
enum State
|
enum State
|
||||||
|
|
|
@ -94,6 +94,8 @@ ResourceTree& ResourceTree::operator=( const ResourceTree& fs )
|
||||||
|
|
||||||
Resource* ResourceTree::FindByHref( const std::string& href )
|
Resource* ResourceTree::FindByHref( const std::string& href )
|
||||||
{
|
{
|
||||||
|
// for the resource that not yet have href (e.g. not yet fetched from server)
|
||||||
|
// their href will be empty.
|
||||||
if ( href.empty() )
|
if ( href.empty() )
|
||||||
return 0 ;
|
return 0 ;
|
||||||
|
|
||||||
|
@ -113,9 +115,23 @@ const Resource* ResourceTree::FindByHref( const std::string& href ) const
|
||||||
/// container. It traverses the tree instead.
|
/// container. It traverses the tree instead.
|
||||||
Resource* ResourceTree::FindByPath( const fs::path& path )
|
Resource* ResourceTree::FindByPath( const fs::path& path )
|
||||||
{
|
{
|
||||||
// not yet implemented
|
Resource *current = m_root ;
|
||||||
assert( false ) ;
|
for ( fs::path::iterator i = path.begin() ; i != path.end() && current != 0 ; ++i )
|
||||||
return false ;
|
{
|
||||||
|
Trace( "path it = %1%", *i ) ;
|
||||||
|
|
||||||
|
// current directory
|
||||||
|
if ( *i == "." )
|
||||||
|
continue ;
|
||||||
|
|
||||||
|
else if ( *i == ".." )
|
||||||
|
current = current->Parent() ;
|
||||||
|
|
||||||
|
else
|
||||||
|
current = current->FindChild( i->filename().string() ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return current ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reinsert should be called when the ID/HREF were updated
|
/// Reinsert should be called when the ID/HREF were updated
|
||||||
|
|
|
@ -176,11 +176,17 @@ bool State::Update( const Entry& e )
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
Resource* State::FindFolderByHref( const std::string& href )
|
Resource* State::FindByHref( const std::string& href )
|
||||||
{
|
{
|
||||||
return m_res.FindByHref( href ) ;
|
return m_res.FindByHref( href ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Resource* State::Find( const fs::path& path )
|
||||||
|
{
|
||||||
|
return m_res.FindByPath( path ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
State::iterator State::begin()
|
State::iterator State::begin()
|
||||||
{
|
{
|
||||||
return m_res.begin() ;
|
return m_res.begin() ;
|
||||||
|
|
|
@ -48,8 +48,9 @@ public :
|
||||||
std::string ChangeStamp() const ;
|
std::string ChangeStamp() const ;
|
||||||
void ChangeStamp( const std::string& cs ) ;
|
void ChangeStamp( const std::string& cs ) ;
|
||||||
|
|
||||||
Resource* FindFolderByHref( const std::string& href ) ;
|
Resource* FindByHref( const std::string& href ) ;
|
||||||
Resource* FindFolderByID( const std::string& id ) ;
|
Resource* FindByID( const std::string& id ) ;
|
||||||
|
Resource* Find( const fs::path& path ) ;
|
||||||
|
|
||||||
iterator begin() ;
|
iterator begin() ;
|
||||||
iterator end() ;
|
iterator end() ;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{ "change_stamp": "", "rtree": { "name": ".", "id": "folder:root", "href": "https:\/\/docs.google.com\/feeds\/default\/private\/full\/folder%3Aroot", "md5": "", "kind": "folder", "mtime": { "sec": 0, "nsec": 0 }, "child": [ { "name": "entry.xml", "id": "", "href": "", "md5": "c0742c0a32b2c909b6f176d17a6992d0", "kind": "file", "mtime": { "sec": 1336796872, "nsec": 404985662 }, "child": [ ] } ] } }
|
|
@ -0,0 +1 @@
|
||||||
|
abc
|
|
@ -22,6 +22,7 @@
|
||||||
#include "Assert.hh"
|
#include "Assert.hh"
|
||||||
|
|
||||||
#include "drive/State.hh"
|
#include "drive/State.hh"
|
||||||
|
#include "util/Log.hh"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -35,9 +36,16 @@ StateTest::StateTest( )
|
||||||
|
|
||||||
void StateTest::TestSync( )
|
void StateTest::TestSync( )
|
||||||
{
|
{
|
||||||
State s( ".grive_state" ) ;
|
State s( TEST_DATA "/test_dir1.state" ) ;
|
||||||
s.FromLocal( TEST_DATA ) ;
|
Resource *r = s.Find( "./folder1/abc.txt" ) ;
|
||||||
s.Write( "" ) ;
|
CPPUNIT_ASSERT( r != 0 ) ;
|
||||||
|
GRUT_ASSERT_EQUAL( r->Name(), "abc.txt" ) ;
|
||||||
|
|
||||||
|
Trace( "state %1% = %2%", r->Name(), r->StateStr() ) ;
|
||||||
|
|
||||||
|
// load directory
|
||||||
|
s.FromLocal( TEST_DATA "/test_dir1" ) ;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end of namespace grut
|
} // end of namespace grut
|
||||||
|
|
Loading…
Reference in New Issue