mirror of https://github.com/vitalif/grive2
replace with FolderSet
parent
37f2066727
commit
149c1c14b0
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include "FolderSet.hh"
|
||||
#include "CommonUri.hh"
|
||||
|
||||
#include "util/Destroy.hh"
|
||||
|
||||
|
@ -27,15 +28,23 @@ namespace gr {
|
|||
|
||||
using namespace details ;
|
||||
|
||||
FolderSet::FolderSet( )
|
||||
FolderSet::FolderSet( ) :
|
||||
m_root( new Collection( ".", root_href ) )
|
||||
{
|
||||
m_set.insert( m_root ) ;
|
||||
}
|
||||
|
||||
FolderSet::FolderSet( const FolderSet& fs )
|
||||
{
|
||||
const Set& s = fs.m_set.get<ByIdentity>() ;
|
||||
for ( Set::const_iterator i = s.begin() ; i != s.end() ; ++i )
|
||||
m_set.insert( new Collection( **i ) ) ;
|
||||
{
|
||||
Collection *c = new Collection( **i ) ;
|
||||
if ( c->SelfHref() == root_href )
|
||||
m_root = c ;
|
||||
|
||||
m_set.insert( c ) ;
|
||||
}
|
||||
}
|
||||
|
||||
FolderSet::~FolderSet( )
|
||||
|
@ -45,6 +54,16 @@ FolderSet::~FolderSet( )
|
|||
std::for_each( s.begin(), s.end(), Destroy() ) ;
|
||||
}
|
||||
|
||||
Collection* FolderSet::Root()
|
||||
{
|
||||
return m_root ;
|
||||
}
|
||||
|
||||
const Collection* FolderSet::Root() const
|
||||
{
|
||||
return m_root ;
|
||||
}
|
||||
|
||||
void FolderSet::Swap( FolderSet& fs )
|
||||
{
|
||||
m_set.swap( fs.m_set ) ;
|
||||
|
@ -86,4 +105,21 @@ bool FolderSet::ReInsert( Collection *coll )
|
|||
return false ;
|
||||
}
|
||||
|
||||
void FolderSet::Insert( Collection *coll )
|
||||
{
|
||||
m_set.insert( coll ) ;
|
||||
}
|
||||
|
||||
void FolderSet::Erase( Collection *coll )
|
||||
{
|
||||
Set& s = m_set.get<ByIdentity>() ;
|
||||
s.erase( s.find( coll ) ) ;
|
||||
}
|
||||
|
||||
void FolderSet::Update( Collection *coll, const Entry& e )
|
||||
{
|
||||
coll->Update( e ) ;
|
||||
ReInsert( coll ) ;
|
||||
}
|
||||
|
||||
} // end of namespace
|
||||
|
|
|
@ -73,8 +73,16 @@ public :
|
|||
// void SetID( Collection *coll, const std::string& id ) ;
|
||||
// void SetHref( Collection *coll, const std::string& href ) ;
|
||||
|
||||
void Insert( Collection *coll ) ;
|
||||
void Erase( Collection *coll ) ;
|
||||
void Update( Collection *coll, const Entry& e ) ;
|
||||
|
||||
Collection* Root() ;
|
||||
const Collection* Root() const ;
|
||||
|
||||
private :
|
||||
details::Folders m_set ;
|
||||
Collection* m_root ;
|
||||
} ;
|
||||
|
||||
} // end of namespace
|
||||
|
|
|
@ -96,7 +96,7 @@ namespace
|
|||
|
||||
typedef ResourceSet::index<ByID>::type IDIdx ;
|
||||
typedef ResourceSet::index<ByPath>::type PathIdx ;
|
||||
|
||||
/*
|
||||
struct ByHref {} ;
|
||||
struct ByIdentity {} ;
|
||||
|
||||
|
@ -110,14 +110,14 @@ namespace
|
|||
> Folders ;
|
||||
|
||||
typedef Folders::index<ByHref>::type FoldersByHref ;
|
||||
typedef Folders::index<ByIdentity>::type FSet ;
|
||||
typedef Folders::index<ByIdentity>::type FSet ;*/
|
||||
}
|
||||
|
||||
struct State::Impl
|
||||
{
|
||||
ResourceSet rs ;
|
||||
Folders folders ;
|
||||
std::string change_stamp ;
|
||||
ResourceSet rs ;
|
||||
FolderSet folders ;
|
||||
std::string change_stamp ;
|
||||
|
||||
std::vector<Entry> unresolved ;
|
||||
} ;
|
||||
|
@ -125,9 +125,6 @@ struct State::Impl
|
|||
State::State( const fs::path& filename ) :
|
||||
m_impl( new Impl )
|
||||
{
|
||||
Collection *root = new Collection( ".", root_href ) ;
|
||||
m_impl->folders.insert( root ) ;
|
||||
|
||||
if ( fs::exists( filename ) )
|
||||
Read( filename );
|
||||
}
|
||||
|
@ -156,15 +153,18 @@ void State::ChangeStamp( const std::string& cs )
|
|||
|
||||
void State::Sync( const fs::path& p )
|
||||
{
|
||||
FoldersByHref& idx = m_impl->folders.get<ByHref>() ;
|
||||
FoldersByHref::iterator it = idx.find( root_href ) ;
|
||||
|
||||
assert( it != idx.end() ) ;
|
||||
Sync( p, *it ) ;
|
||||
// FoldersByHref& idx = m_impl->folders.get<ByHref>() ;
|
||||
// FoldersByHref::iterator it = idx.find( root_href ) ;
|
||||
|
||||
// Collection *root = m_impl->folders.FindByHref( root_href ) ;
|
||||
// assert( root != 0 ) ;
|
||||
Sync( p, m_impl->folders.Root() ) ;
|
||||
}
|
||||
|
||||
void State::Sync( const fs::path& p, Collection *folder )
|
||||
{
|
||||
assert( folder != 0 ) ;
|
||||
|
||||
// Trace( "synchronizing = %1%", p ) ;
|
||||
for ( fs::directory_iterator i( p ) ; i != fs::directory_iterator() ; ++i )
|
||||
{
|
||||
|
@ -263,33 +263,35 @@ std::size_t State::TryResolveEntry()
|
|||
|
||||
bool State::Update( const Entry& e )
|
||||
{
|
||||
FoldersByHref& folders = m_impl->folders.get<ByHref>() ;
|
||||
FoldersByHref::iterator i = folders.find( e.ParentHref() ) ;
|
||||
if ( i != folders.end() )
|
||||
// FoldersByHref& folders = m_impl->folders.get<ByHref>() ;
|
||||
// FoldersByHref::iterator i = folders.find( e.ParentHref() ) ;
|
||||
Collection *parent = m_impl->folders.FindByHref( e.ParentHref() ) ;
|
||||
if ( parent != 0 )
|
||||
{
|
||||
Trace( "found parent of folder %1%: %2%", e.Title(), (*i)->Title() ) ;
|
||||
Trace( "found parent of folder %1%: %2%", e.Title(), parent->Title() ) ;
|
||||
|
||||
// see if the entry already exist in local
|
||||
Collection *child = (*i)->FindChild( e.Title() ) ;
|
||||
Collection *child = parent->FindChild( e.Title() ) ;
|
||||
if ( child != 0 )
|
||||
{
|
||||
// since we are updating the ID and Href, we need to remove it and re-add it.
|
||||
FSet& fs = m_impl->folders.get<ByIdentity>() ;
|
||||
FSet::iterator c = fs.find( child ) ;
|
||||
|
||||
if ( c != fs.end() )
|
||||
fs.erase( c ) ;
|
||||
|
||||
child->Update( e ) ;
|
||||
folders.insert( child ) ;
|
||||
m_impl->folders.Update( child, e ) ;
|
||||
// FSet& fs = m_impl->folders.get<ByIdentity>() ;
|
||||
// FSet::iterator c = fs.find( child ) ;
|
||||
//
|
||||
// if ( c != fs.end() )
|
||||
// fs.erase( c ) ;
|
||||
//
|
||||
// child->Update( e ) ;
|
||||
// folders.insert( child ) ;
|
||||
}
|
||||
|
||||
// folder entry exist in google drive, but not local.
|
||||
else
|
||||
{
|
||||
child = new Collection( e ) ;
|
||||
(*i)->AddChild( child ) ;
|
||||
folders.insert( child ) ;
|
||||
parent->AddChild( child ) ;
|
||||
m_impl->folders.Insert( child ) ;
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
@ -299,9 +301,10 @@ bool State::Update( const Entry& e )
|
|||
|
||||
Collection* State::FindFolderByHref( const std::string& href )
|
||||
{
|
||||
FoldersByHref& folders = m_impl->folders.get<ByHref>() ;
|
||||
FoldersByHref::iterator i = folders.find( href ) ;
|
||||
return i != folders.end() ? *i : 0 ;
|
||||
// FoldersByHref& folders = m_impl->folders.get<ByHref>() ;
|
||||
// FoldersByHref::iterator i = folders.find( href ) ;
|
||||
// return i != folders.end() ? *i : 0 ;
|
||||
return m_impl->folders.FindByHref( href ) ;
|
||||
}
|
||||
|
||||
} // end of namespace
|
||||
|
|
Loading…
Reference in New Issue