Skip to content

Commit

Permalink
Merge pull request Grive#100 from justinharding/mtimebranch
Browse files Browse the repository at this point in the history
store modified time of file in m_mtime instead of passing value as param
  • Loading branch information
nestal committed Jul 23, 2012
2 parents c6a1c47 + 96227d3 commit 271e4d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
24 changes: 13 additions & 11 deletions libgrive/src/drive/Resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,18 @@ void Resource::Sync( http::Agent *http, DateTime& sync_time )
assert( m_state != unknown ) ;
assert( !IsRoot() || m_state == sync ) ; // root folder is already synced

SyncSelf( http, sync_time ) ;
SyncSelf( http ) ;
// we want the server sync time, so we will take the server time of the last file uploaded to store as the sync time
// m_mtime is updated to server modified time when the file is uploaded
sync_time = std::max(sync_time, m_mtime);

// 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, boost::ref(sync_time) ) ) ;
}

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

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

Expand All @@ -404,7 +407,7 @@ void Resource::SyncSelf( http::Agent* http, DateTime& sync_time )

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

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

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

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

bool Resource::Create( http::Agent* http, DateTime& sync_time )
bool Resource::Create( http::Agent* http)
{
assert( http != 0 ) ;
assert( m_parent != 0 ) ;
Expand Down Expand Up @@ -563,7 +566,7 @@ bool Resource::Create( http::Agent* http, DateTime& sync_time )
}
else if ( !m_parent->m_create.empty() )
{
return Upload( http, m_parent->m_create + "?convert=false", true, sync_time ) ;
return Upload( http, m_parent->m_create + "?convert=false", true ) ;
}
else
{
Expand All @@ -575,8 +578,7 @@ bool Resource::Create( http::Agent* http, DateTime& sync_time )
bool Resource::Upload(
http::Agent* http,
const std::string& link,
bool post,
DateTime& sync_time )
bool post)
{
assert( http != 0 ) ;

Expand Down Expand Up @@ -612,7 +614,7 @@ bool Resource::Upload(

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

return true ;
}
Expand Down
8 changes: 4 additions & 4 deletions libgrive/src/drive/Resource.hh
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ private :
void SetState( State new_state ) ;

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

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

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

private :
std::string m_name ;
Expand Down

0 comments on commit 271e4d7

Please sign in to comment.