Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sending a pull request #92

Merged
merged 1 commit into from Jul 16, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 12 additions & 11 deletions libgrive/src/drive/Resource.cc
Expand Up @@ -360,20 +360,20 @@ Resource* Resource::FindChild( const std::string& name )
}

// try to change the state to "sync"
void Resource::Sync( http::Agent *http, const http::Header& auth )
void Resource::Sync( http::Agent *http, const http::Header& auth, DateTime& sync_time )
{
assert( m_state != unknown ) ;
assert( !IsRoot() || m_state == sync ) ; // root folder is already synced

SyncSelf( http, auth ) ;
SyncSelf( http, auth, sync_time ) ;

// if myself is deleted, no need to do the childrens
if ( m_state != local_deleted && m_state != remote_deleted )
std::for_each( m_child.begin(), m_child.end(),
boost::bind( &Resource::Sync, _1, http, auth ) ) ;
boost::bind( &Resource::Sync, _1, http, auth, boost::ref(sync_time) ) ) ;
}

void Resource::SyncSelf( http::Agent* http, const http::Header& auth )
void Resource::SyncSelf( http::Agent* http, const http::Header& auth, DateTime& sync_time )
{
assert( !IsRoot() || m_state == sync ) ; // root is always sync
assert( IsRoot() || http == 0 || fs::is_directory( m_parent->Path() ) ) ;
Expand All @@ -387,7 +387,7 @@ void Resource::SyncSelf( http::Agent* http, const http::Header& auth )
case local_new :
Log( "sync %1% doesn't exist in server, uploading", path, log::info ) ;

if ( http != 0 && Create( http, auth ) )
if ( http != 0 && Create( http, auth, sync_time ) )
m_state = sync ;
break ;

Expand All @@ -399,7 +399,7 @@ void Resource::SyncSelf( http::Agent* http, const http::Header& auth )

case local_changed :
Log( "sync %1% changed in local. uploading", path, log::info ) ;
if ( http != 0 && EditContent( http, auth ) )
if ( http != 0 && EditContent( http, auth, sync_time ) )
m_state = sync ;
break ;

Expand Down Expand Up @@ -512,7 +512,7 @@ void Resource::Download( http::Agent* http, const fs::path& file, const http::He
}
}

bool Resource::EditContent( http::Agent* http, const http::Header& auth )
bool Resource::EditContent( http::Agent* http, const http::Header& auth, DateTime& sync_time )
{
assert( http != 0 ) ;
assert( m_parent != 0 ) ;
Expand All @@ -525,10 +525,10 @@ bool Resource::EditContent( http::Agent* http, const http::Header& auth )
return false ;
}

return Upload( http, m_edit, auth, false ) ;
return Upload( http, m_edit, auth, false, sync_time ) ;
}

bool Resource::Create( http::Agent* http, const http::Header& auth )
bool Resource::Create( http::Agent* http, const http::Header& auth, DateTime& sync_time )
{
assert( http != 0 ) ;
assert( m_parent != 0 ) ;
Expand Down Expand Up @@ -558,7 +558,7 @@ bool Resource::Create( http::Agent* http, const http::Header& auth )
}
else if ( !m_parent->m_create.empty() )
{
return Upload( http, m_parent->m_create + "?convert=false", auth, true ) ;
return Upload( http, m_parent->m_create + "?convert=false", auth, true, sync_time ) ;
}
else
{
Expand All @@ -567,7 +567,7 @@ bool Resource::Create( http::Agent* http, const http::Header& auth )
}
}

bool Resource::Upload( http::Agent* http, const std::string& link, const http::Header& auth, bool post )
bool Resource::Upload( http::Agent* http, const std::string& link, const http::Header& auth, bool post, DateTime& sync_time )
{
assert( http != 0 ) ;

Expand Down Expand Up @@ -611,6 +611,7 @@ bool Resource::Upload( http::Agent* http, const std::string& link, const http::H

http->Put( uplink, data, &xml, uphdr ) ;
AssignIDs( Entry( xml.Response() ) ) ;
sync_time = std::max(Entry(xml.Response()).MTime(), sync_time);

return true ;
}
Expand Down
10 changes: 5 additions & 5 deletions libgrive/src/drive/Resource.hh
Expand Up @@ -77,7 +77,7 @@ public :
void FromRemote( const Entry& remote, const DateTime& last_sync ) ;
void FromLocal( const DateTime& last_sync ) ;

void Sync( http::Agent* http, const http::Header& auth ) ;
void Sync( http::Agent* http, const http::Header& auth, DateTime& sync_time ) ;

// children access
iterator begin() const ;
Expand Down Expand Up @@ -125,9 +125,9 @@ private :
void SetState( State new_state ) ;

void Download( http::Agent* http, const fs::path& file, const http::Header& auth ) const ;
bool EditContent( http::Agent* http, const http::Header& auth ) ;
bool Create( http::Agent* http, const http::Header& auth ) ;
bool Upload( http::Agent* http, const std::string& link, const http::Header& auth, bool post ) ;
bool EditContent( http::Agent* http, const http::Header& auth, DateTime& sync_time ) ;
bool Create( http::Agent* http, const http::Header& auth, DateTime& sync_time ) ;
bool Upload( http::Agent* http, const std::string& link, const http::Header& auth, bool post, DateTime& sync_time ) ;

void FromRemoteFolder( const Entry& remote, const DateTime& last_sync ) ;
void FromRemoteFile( const Entry& remote, const DateTime& last_sync ) ;
Expand All @@ -136,7 +136,7 @@ private :
void DeleteRemote( http::Agent* http, const http::Header& auth ) ;

void AssignIDs( const Entry& remote ) ;
void SyncSelf( http::Agent* http, const http::Header& auth ) ;
void SyncSelf( http::Agent* http, const http::Header& auth, DateTime& sync_time ) ;

private :
std::string m_name ;
Expand Down
16 changes: 14 additions & 2 deletions libgrive/src/drive/State.cc
Expand Up @@ -264,8 +264,20 @@ void State::Write( const fs::path& filename ) const

void State::Sync( http::Agent *http, const http::Header& auth )
{
m_res.Root()->Sync( http, auth ) ;
m_last_sync = DateTime::Now() ;
// set the last sync time from the time returned by the server for the last file synced
// if the sync time hasn't changed (i.e. now files have been uploaded)
// set the last sync time to the time on the client
// ideally because we compare server file times to the last sync time
// the last sync time would always be a server time rather than a client time
// TODO - WARNING - do we use the last sync time to compare to client file times
// need to check if this introduces a new problem
DateTime last_sync_time = m_last_sync;
m_res.Root()->Sync( http, auth, last_sync_time ) ;
if (last_sync_time == m_last_sync) {
m_last_sync = DateTime::Now();
} else {
m_last_sync = last_sync_time;
}
}

long State::ChangeStamp() const
Expand Down