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"] == "" )
|
||||
continue ;
|
||||
|
||||
Entry file( *i ) ;
|
||||
if ( file.Kind() != "folder" )
|
||||
Entry entry( *i ) ;
|
||||
if ( entry.Kind() != "folder" )
|
||||
{
|
||||
Resource *p = m_state.FindFolderByHref( file.ParentHref() ) ;
|
||||
if ( file.Filename().empty() )
|
||||
Log( "file \"%1%\" is a google document, ignored", file.Title(), log::info ) ;
|
||||
Resource *parent = m_state.FindByHref( entry.ParentHref() ) ;
|
||||
if ( entry.Filename().empty() )
|
||||
Log( "file \"%1%\" is a google document, ignored", entry.Title(), log::info ) ;
|
||||
|
||||
else if ( file.ParentHref().empty() || p == 0 || !p->IsInRootTree() )
|
||||
Log( "file \"%1%\" parent doesn't exist, ignored", file.Title(), log::info ) ;
|
||||
else if ( parent == 0 || !parent->IsInRootTree() )
|
||||
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",
|
||||
file.Title(), p->Name(), log::info ) ;
|
||||
entry.Title(), parent->Name(), log::info ) ;
|
||||
|
||||
else
|
||||
m_state.FromRemote( file ) ;
|
||||
m_state.FromRemote( entry ) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ public :
|
|||
|
||||
private :
|
||||
void ConstructDirTree( http::Agent *http ) ;
|
||||
void file();
|
||||
|
||||
private :
|
||||
OAuth2& m_auth ;
|
||||
|
|
|
@ -154,11 +154,13 @@ std::string Resource::ResourceID() const
|
|||
|
||||
const Resource* Resource::Parent() const
|
||||
{
|
||||
assert( m_parent == 0 || m_parent->IsFolder() ) ;
|
||||
return m_parent ;
|
||||
}
|
||||
|
||||
Resource* Resource::Parent()
|
||||
{
|
||||
assert( m_parent == 0 || m_parent->IsFolder() ) ;
|
||||
return m_parent ;
|
||||
}
|
||||
|
||||
|
@ -182,6 +184,7 @@ void Resource::Swap( Resource& coll )
|
|||
m_entry.Swap( coll.m_entry ) ;
|
||||
std::swap( m_parent, coll.m_parent ) ;
|
||||
m_child.swap( coll.m_child ) ;
|
||||
std::swap( m_state, coll.m_state ) ;
|
||||
}
|
||||
|
||||
bool Resource::IsFolder() const
|
||||
|
@ -395,6 +398,13 @@ std::ostream& operator<<( std::ostream& os, Resource::State s )
|
|||
return os << state[s] ;
|
||||
}
|
||||
|
||||
std::string Resource::StateStr() const
|
||||
{
|
||||
std::ostringstream ss ;
|
||||
ss << m_state ;
|
||||
return ss.str() ;
|
||||
}
|
||||
|
||||
} // end of namespace
|
||||
|
||||
namespace std
|
||||
|
|
|
@ -83,6 +83,8 @@ public :
|
|||
iterator end() const ;
|
||||
std::size_t size() const ;
|
||||
|
||||
std::string StateStr() const ;
|
||||
|
||||
private :
|
||||
/// State of the resource. indicating what to do with the resource
|
||||
enum State
|
||||
|
|
|
@ -94,6 +94,8 @@ ResourceTree& ResourceTree::operator=( const ResourceTree& fs )
|
|||
|
||||
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() )
|
||||
return 0 ;
|
||||
|
||||
|
@ -113,9 +115,23 @@ const Resource* ResourceTree::FindByHref( const std::string& href ) const
|
|||
/// container. It traverses the tree instead.
|
||||
Resource* ResourceTree::FindByPath( const fs::path& path )
|
||||
{
|
||||
// not yet implemented
|
||||
assert( false ) ;
|
||||
return false ;
|
||||
Resource *current = m_root ;
|
||||
for ( fs::path::iterator i = path.begin() ; i != path.end() && current != 0 ; ++i )
|
||||
{
|
||||
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
|
||||
|
|
|
@ -176,11 +176,17 @@ bool State::Update( const Entry& e )
|
|||
return false ;
|
||||
}
|
||||
|
||||
Resource* State::FindFolderByHref( const std::string& href )
|
||||
Resource* State::FindByHref( const std::string& href )
|
||||
{
|
||||
return m_res.FindByHref( href ) ;
|
||||
}
|
||||
|
||||
Resource* State::Find( const fs::path& path )
|
||||
{
|
||||
return m_res.FindByPath( path ) ;
|
||||
}
|
||||
|
||||
|
||||
State::iterator State::begin()
|
||||
{
|
||||
return m_res.begin() ;
|
||||
|
|
|
@ -48,8 +48,9 @@ public :
|
|||
std::string ChangeStamp() const ;
|
||||
void ChangeStamp( const std::string& cs ) ;
|
||||
|
||||
Resource* FindFolderByHref( const std::string& href ) ;
|
||||
Resource* FindFolderByID( const std::string& id ) ;
|
||||
Resource* FindByHref( const std::string& href ) ;
|
||||
Resource* FindByID( const std::string& id ) ;
|
||||
Resource* Find( const fs::path& path ) ;
|
||||
|
||||
iterator begin() ;
|
||||
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 "drive/State.hh"
|
||||
#include "util/Log.hh"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
@ -35,9 +36,16 @@ StateTest::StateTest( )
|
|||
|
||||
void StateTest::TestSync( )
|
||||
{
|
||||
State s( ".grive_state" ) ;
|
||||
s.FromLocal( TEST_DATA ) ;
|
||||
s.Write( "" ) ;
|
||||
State s( TEST_DATA "/test_dir1.state" ) ;
|
||||
Resource *r = s.Find( "./folder1/abc.txt" ) ;
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue