mirror of https://github.com/vitalif/grive2
Fix 412's on reupload. Fixes #5
parent
37b2cf3102
commit
82705f39b0
|
@ -386,6 +386,7 @@ void Resource::SyncSelf( Syncer* syncer, const Val& options )
|
|||
case local_new :
|
||||
Log( "sync %1% doesn't exist in server, uploading", path, log::info ) ;
|
||||
|
||||
// FIXME: (?) do not write new timestamp on failed upload
|
||||
if ( syncer && syncer->Create( this ) )
|
||||
m_state = sync ;
|
||||
break ;
|
||||
|
|
|
@ -90,16 +90,6 @@ bool Syncer2::Create( Resource *res )
|
|||
|
||||
bool Syncer2::Upload( Resource *res )
|
||||
{
|
||||
File file( res->Path() ) ;
|
||||
std::ostringstream xcontent_len ;
|
||||
xcontent_len << "Content-Length: " << file.Size() ;
|
||||
|
||||
http::Header hdr ;
|
||||
hdr.Add( "Content-Type: application/octet-stream" ) ;
|
||||
hdr.Add( xcontent_len.str() ) ;
|
||||
if ( !res->ETag().empty() )
|
||||
hdr.Add( "If-Match: " + res->ETag() ) ;
|
||||
|
||||
Val meta;
|
||||
meta.Add( "title", Val( res->Name() ) );
|
||||
if ( res->IsFolder() )
|
||||
|
@ -129,40 +119,43 @@ bool Syncer2::Upload( Resource *res )
|
|||
else
|
||||
http_code = m_http->Put( feeds::files + "/" + res->ResourceID(), json_meta, &vrsp, hdr2 ) ;
|
||||
valr = vrsp.Response();
|
||||
assert( !(valr["id"].Str().empty()) );
|
||||
assert( !( valr["id"].Str().empty() ) );
|
||||
}
|
||||
|
||||
bool retrying = false;
|
||||
while ( true )
|
||||
if ( !res->IsFolder() )
|
||||
{
|
||||
if ( retrying )
|
||||
while ( true )
|
||||
{
|
||||
file.Seek( 0, SEEK_SET );
|
||||
os::Sleep( 5 );
|
||||
}
|
||||
File file( res->Path() ) ;
|
||||
std::ostringstream xcontent_len ;
|
||||
xcontent_len << "Content-Length: " << file.Size() ;
|
||||
|
||||
http::Header hdr ;
|
||||
hdr.Add( "Content-Type: application/octet-stream" ) ;
|
||||
hdr.Add( xcontent_len.str() ) ;
|
||||
if ( valr.Has( "etag" ) )
|
||||
hdr.Add( "If-Match: " + valr["etag"].Str() ) ;
|
||||
|
||||
if ( !res->IsFolder() )
|
||||
{
|
||||
http::ValResponse vrsp;
|
||||
long http_code = m_http->Put( upload_base + "/" + valr["id"].Str() + "?uploadType=media", &file, &vrsp, hdr ) ;
|
||||
if ( http_code == 410 || http_code == 412 )
|
||||
{
|
||||
Log( "request failed with %1%, retrying whole upload in 5s", http_code, log::warning ) ;
|
||||
retrying = true;
|
||||
continue;
|
||||
os::Sleep( 5 );
|
||||
}
|
||||
else
|
||||
{
|
||||
valr = vrsp.Response() ;
|
||||
assert( !( valr["id"].Str().empty() ) );
|
||||
break ;
|
||||
}
|
||||
valr = vrsp.Response();
|
||||
assert( !(valr["id"].Str().empty()) );
|
||||
}
|
||||
|
||||
if ( retrying )
|
||||
Log( "upload succeeded on retry", log::warning );
|
||||
Entry2 responseEntry = Entry2( valr );
|
||||
AssignIDs( res, responseEntry ) ;
|
||||
AssignMTime( res, responseEntry.MTime() );
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Entry2 responseEntry = Entry2( valr ) ;
|
||||
AssignIDs( res, responseEntry ) ;
|
||||
AssignMTime( res, responseEntry.MTime() ) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue