mirror of https://github.com/vitalif/grive2
improved support for changes feed
parent
55572c7fc4
commit
f0ce00ca7b
|
@ -104,12 +104,12 @@ Drive::Drive( OAuth2& auth, const Json& options ) :
|
||||||
|
|
||||||
void Drive::FromRemote( const Entry& entry )
|
void Drive::FromRemote( const Entry& entry )
|
||||||
{
|
{
|
||||||
if ( entry.Kind() != "folder" && !entry.ContentSrc().empty() )
|
// if ( entry.Kind() != "folder" && !entry.ContentSrc().empty() )
|
||||||
{
|
// {
|
||||||
Resource *parent = m_state.FindByHref( entry.ParentHref() ) ;
|
Resource *parent = m_state.FindByHref( entry.ParentHref() ) ;
|
||||||
std::string fn = entry.Filename() ;
|
std::string fn = entry.Filename() ;
|
||||||
|
|
||||||
if ( fn.empty() )
|
if ( fn.empty() || entry.ContentSrc().empty() )
|
||||||
Log( "file \"%1%\" is a google document, ignored", entry.Title(), log::verbose ) ;
|
Log( "file \"%1%\" is a google document, ignored", entry.Title(), log::verbose ) ;
|
||||||
|
|
||||||
else if ( fn.find('/') != fn.npos )
|
else if ( fn.find('/') != fn.npos )
|
||||||
|
@ -124,7 +124,7 @@ void Drive::FromRemote( const Entry& entry )
|
||||||
|
|
||||||
else
|
else
|
||||||
m_state.FromRemote( entry ) ;
|
m_state.FromRemote( entry ) ;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void Drive::FromChange( const Entry& entry )
|
void Drive::FromChange( const Entry& entry )
|
||||||
|
@ -134,11 +134,13 @@ void Drive::FromChange( const Entry& entry )
|
||||||
if ( entry.IsRemoved() )
|
if ( entry.IsRemoved() )
|
||||||
Log( "file \"%1%\" represents a deletion, ignored", entry.Title(), log::verbose ) ;
|
Log( "file \"%1%\" represents a deletion, ignored", entry.Title(), log::verbose ) ;
|
||||||
|
|
||||||
else if ( fn.empty() )
|
// else if ( fn.empty() )
|
||||||
Log( "file \"%1%\" is a google document, ignored", entry.Title(), log::verbose ) ;
|
// Log( "file \"%1%\" is a google document, ignored", entry.Title(), log::verbose ) ;
|
||||||
|
//
|
||||||
else if ( !entry.ContentSrc().empty() )
|
// else if ( !entry.ContentSrc().empty() )
|
||||||
m_state.FromChange( entry ) ;
|
// m_state.FromRemote( entry ) ;
|
||||||
|
else
|
||||||
|
FromRemote( entry ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Drive::SaveState()
|
void Drive::SaveState()
|
||||||
|
|
|
@ -179,6 +179,11 @@ long Entry::ChangeStamp() const
|
||||||
return m_change_stamp ;
|
return m_change_stamp ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Entry::IsChange() const
|
||||||
|
{
|
||||||
|
return m_change_stamp != -1 ;
|
||||||
|
}
|
||||||
|
|
||||||
bool Entry::IsRemoved() const
|
bool Entry::IsRemoved() const
|
||||||
{
|
{
|
||||||
return m_is_removed ;
|
return m_is_removed ;
|
||||||
|
|
|
@ -63,6 +63,8 @@ public :
|
||||||
std::string EditLink() const ;
|
std::string EditLink() const ;
|
||||||
std::string CreateLink() const ;
|
std::string CreateLink() const ;
|
||||||
long ChangeStamp() const ;
|
long ChangeStamp() const ;
|
||||||
|
|
||||||
|
bool IsChange() const ;
|
||||||
bool IsRemoved() const ;
|
bool IsRemoved() const ;
|
||||||
|
|
||||||
const std::vector<std::string>& ParentHrefs() const ;
|
const std::vector<std::string>& ParentHrefs() const ;
|
||||||
|
|
|
@ -145,12 +145,16 @@ void Resource::FromRemote( const Entry& remote, const DateTime& last_sync )
|
||||||
|
|
||||||
void Resource::AssignIDs( const Entry& remote )
|
void Resource::AssignIDs( const Entry& remote )
|
||||||
{
|
{
|
||||||
m_id = remote.ResourceID() ;
|
// the IDs from change feed entries are different
|
||||||
m_href = remote.SelfHref() ;
|
if ( !remote.IsChange() )
|
||||||
m_edit = remote.EditLink() ;
|
{
|
||||||
m_create = remote.CreateLink() ;
|
m_id = remote.ResourceID() ;
|
||||||
m_content = remote.ContentSrc() ;
|
m_href = remote.SelfHref() ;
|
||||||
m_etag = remote.ETag() ;
|
m_edit = remote.EditLink() ;
|
||||||
|
m_create = remote.CreateLink() ;
|
||||||
|
m_content = remote.ContentSrc() ;
|
||||||
|
m_etag = remote.ETag() ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::FromRemoteFile( const Entry& remote, const DateTime& last_sync )
|
void Resource::FromRemoteFile( const Entry& remote, const DateTime& last_sync )
|
||||||
|
@ -200,7 +204,7 @@ void Resource::FromRemoteFile( const Entry& remote, const DateTime& last_sync )
|
||||||
// use mtime to check which one is more recent
|
// use mtime to check which one is more recent
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert( m_state == local_new || m_state == local_changed || m_state == remote_deleted ) ;
|
assert( m_state != unknown ) ;
|
||||||
|
|
||||||
// if remote is modified
|
// if remote is modified
|
||||||
if ( remote.MTime() > m_mtime )
|
if ( remote.MTime() > m_mtime )
|
||||||
|
@ -236,7 +240,6 @@ void Resource::FromLocal( const DateTime& last_sync )
|
||||||
m_mtime = os::FileCTime( path ) ;
|
m_mtime = os::FileCTime( path ) ;
|
||||||
m_state = ( m_mtime > last_sync ? local_new : remote_deleted ) ;
|
m_state = ( m_mtime > last_sync ? local_new : remote_deleted ) ;
|
||||||
|
|
||||||
// m_entry.FromLocal( path ) ;
|
|
||||||
m_name = path.filename().string() ;
|
m_name = path.filename().string() ;
|
||||||
m_kind = fs::is_directory(path) ? "folder" : "file" ;
|
m_kind = fs::is_directory(path) ? "folder" : "file" ;
|
||||||
m_md5 = fs::is_directory(path) ? "" : crypt::MD5::Get( path ) ;
|
m_md5 = fs::is_directory(path) ? "" : crypt::MD5::Get( path ) ;
|
||||||
|
|
|
@ -113,6 +113,9 @@ void State::FromRemote( const Entry& e )
|
||||||
if ( IsIgnore( e.Name() ) )
|
if ( IsIgnore( e.Name() ) )
|
||||||
Log( "%1% %2% is ignored by grive", e.Kind(), e.Name(), log::verbose ) ;
|
Log( "%1% %2% is ignored by grive", e.Kind(), e.Name(), log::verbose ) ;
|
||||||
|
|
||||||
|
else if ( e.IsChange() )
|
||||||
|
FromChange( e ) ;
|
||||||
|
|
||||||
else if ( !Update( e ) )
|
else if ( !Update( e ) )
|
||||||
{
|
{
|
||||||
m_unresolved.push_back( e ) ;
|
m_unresolved.push_back( e ) ;
|
||||||
|
@ -150,17 +153,18 @@ std::size_t State::TryResolveEntry()
|
||||||
|
|
||||||
void State::FromChange( const Entry& e )
|
void State::FromChange( const Entry& e )
|
||||||
{
|
{
|
||||||
if ( IsIgnore( e.Name() ) )
|
assert( e.IsChange() ) ;
|
||||||
Log( "%1% %2% is ignored by grive", e.Kind(), e.Name(), log::verbose ) ;
|
assert( !IsIgnore( e.Name() ) ) ;
|
||||||
|
|
||||||
// entries in the change feed is always treated as newer in remote,
|
// entries in the change feed is always treated as newer in remote,
|
||||||
// so we override the last sync time to 0
|
// so we override the last sync time to 0
|
||||||
else if ( Resource *res = m_res.FindByHref( e.AltSelf() ) )
|
if ( Resource *res = m_res.FindByHref( e.AltSelf() ) )
|
||||||
m_res.Update( res, e, DateTime() ) ;
|
m_res.Update( res, e, DateTime() ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool State::Update( const Entry& e )
|
bool State::Update( const Entry& e )
|
||||||
{
|
{
|
||||||
|
assert( !e.IsChange() ) ;
|
||||||
assert( !e.ParentHref().empty() ) ;
|
assert( !e.ParentHref().empty() ) ;
|
||||||
|
|
||||||
if ( Resource *res = m_res.FindByHref( e.SelfHref() ) )
|
if ( Resource *res = m_res.FindByHref( e.SelfHref() ) )
|
||||||
|
@ -173,7 +177,7 @@ bool State::Update( const Entry& e )
|
||||||
assert( parent->IsFolder() ) ;
|
assert( parent->IsFolder() ) ;
|
||||||
|
|
||||||
// see if the entry already exist in local
|
// see if the entry already exist in local
|
||||||
std::string name = ( e.Kind() == "folder" ? e.Title() : e.Filename() ) ;
|
std::string name = e.Name() ;
|
||||||
Resource *child = parent->FindChild( name ) ;
|
Resource *child = parent->FindChild( name ) ;
|
||||||
if ( child != 0 )
|
if ( child != 0 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,7 +49,6 @@ public :
|
||||||
|
|
||||||
void FromLocal( const fs::path& p ) ;
|
void FromLocal( const fs::path& p ) ;
|
||||||
void FromRemote( const Entry& e ) ;
|
void FromRemote( const Entry& e ) ;
|
||||||
void FromChange( const Entry& e ) ;
|
|
||||||
void ResolveEntry() ;
|
void ResolveEntry() ;
|
||||||
|
|
||||||
void Read( const fs::path& filename ) ;
|
void Read( const fs::path& filename ) ;
|
||||||
|
@ -69,6 +68,7 @@ public :
|
||||||
|
|
||||||
private :
|
private :
|
||||||
void FromLocal( const fs::path& p, Resource *folder ) ;
|
void FromLocal( const fs::path& p, Resource *folder ) ;
|
||||||
|
void FromChange( const Entry& e ) ;
|
||||||
bool Update( const Entry& e ) ;
|
bool Update( const Entry& e ) ;
|
||||||
std::size_t TryResolveEntry() ;
|
std::size_t TryResolveEntry() ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue