mirror of https://github.com/vitalif/grive2
refactored a bit for the fix in #76
parent
dc89aee613
commit
daa1fe9ca3
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
grive: an GPL program to sync a local directory with Google Drive
|
||||
Copyright (C) 2012 Wan Wai Ho
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation version 2
|
||||
of the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "CommonUri.hh"
|
||||
#include <boost/format.hpp>
|
||||
|
||||
namespace gr {
|
||||
|
||||
std::string ChangesFeed( int changestamp )
|
||||
{
|
||||
boost::format feed( feed_changes + "?start-index=%1%" ) ;
|
||||
return changestamp > 0 ? (feed%changestamp).str() : feed_changes ;
|
||||
}
|
||||
|
||||
}
|
|
@ -31,4 +31,6 @@ namespace gr
|
|||
"https://docs.google.com/feeds/default/private/full/folder%3Aroot" ;
|
||||
const std::string root_create =
|
||||
"https://docs.google.com/feeds/upload/create-session/default/private/full" ;
|
||||
|
||||
std::string ChangesFeed( int changestamp ) ;
|
||||
}
|
||||
|
|
|
@ -84,7 +84,6 @@ void Drive::FromChange( const Entry& entry )
|
|||
Log( "file \"%1%\" represents a deletion, ignored", entry.Title(), log::verbose ) ;
|
||||
|
||||
// folders go directly
|
||||
|
||||
else
|
||||
m_state.FromRemote( entry ) ;
|
||||
}
|
||||
|
@ -101,7 +100,6 @@ void Drive::SyncFolders( http::Agent *http )
|
|||
Log( "Synchronizing folders", log::info ) ;
|
||||
|
||||
http::XmlResponse xml ;
|
||||
// http::ResponseLog log( "dir-", ".xml", &xml ) ;
|
||||
http->Get( feed_base + "/-/folder?max-results=50&showroot=true", &xml, m_http_hdr ) ;
|
||||
|
||||
Feed feed( xml.Response() ) ;
|
||||
|
@ -157,9 +155,9 @@ void Drive::DetectChanges()
|
|||
// pull the changes feed
|
||||
if ( prev_stamp != -1 )
|
||||
{
|
||||
http::ResponseLog log( "/tmp/changes-", ".xml", &xrsp ) ;
|
||||
Log( "Detecting changes from last sync", log::info ) ;
|
||||
boost::format changes_uri( "https://docs.google.com/feeds/default/private/changes?start-index=%1%" ) ;
|
||||
http.Get( (changes_uri%(prev_stamp+1)).str(), &xrsp, m_http_hdr ) ;
|
||||
http.Get( ChangesFeed(prev_stamp+1), &log, m_http_hdr ) ;
|
||||
|
||||
Feed changes( xrsp.Response() ) ;
|
||||
std::for_each( changes.begin(), changes.end(), boost::bind( &Drive::FromChange, this, _1 ) ) ;
|
||||
|
@ -185,20 +183,9 @@ void Drive::UpdateChangeStamp( http::Agent *http )
|
|||
{
|
||||
assert( http != 0 ) ;
|
||||
|
||||
http::XmlResponse xrsp ;
|
||||
|
||||
// get changed feed
|
||||
std::string url;
|
||||
if (m_state.ChangeStamp() != -1)
|
||||
{
|
||||
boost::format changes_uri( "https://docs.google.com/feeds/default/private/changes?start-index=%1%" ) ;
|
||||
url = (changes_uri%(m_state.ChangeStamp()+1)).str();
|
||||
}
|
||||
else
|
||||
{
|
||||
url = "https://docs.google.com/feeds/default/private/changes";
|
||||
}
|
||||
http->Get( url, &xrsp, m_http_hdr ) ;
|
||||
http::XmlResponse xrsp ;
|
||||
http->Get( ChangesFeed(m_state.ChangeStamp()+1), &xrsp, m_http_hdr ) ;
|
||||
|
||||
// we should go through the changes to see if it was really Grive to made that change
|
||||
// maybe by recording the updated timestamp and compare it?
|
||||
|
|
Loading…
Reference in New Issue