From 81817b3538f9ad00f75c5664c5ef3aafcb452c66 Mon Sep 17 00:00:00 2001 From: MrCoffee77 Date: Tue, 10 Feb 2015 07:23:49 +0100 Subject: [PATCH] Update Resource.cc Fix for HTTP-Stat 400 while uploading. It will ignore the file and continue. --- libgrive/src/drive/Resource.cc | 75 ++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/libgrive/src/drive/Resource.cc b/libgrive/src/drive/Resource.cc index 4010cab2..25a6f26f 100644 --- a/libgrive/src/drive/Resource.cc +++ b/libgrive/src/drive/Resource.cc @@ -582,41 +582,46 @@ bool Resource::Upload( bool post) { assert( http != 0 ) ; - - File file( Path() ) ; - std::ostringstream xcontent_len ; - xcontent_len << "X-Upload-Content-Length: " << file.Size() ; - - http::Header hdr ; - hdr.Add( "Content-Type: application/atom+xml" ) ; - hdr.Add( "X-Upload-Content-Type: application/octet-stream" ) ; - hdr.Add( xcontent_len.str() ) ; - hdr.Add( "If-Match: " + m_etag ) ; - hdr.Add( "Expect:" ) ; - - std::string meta = (boost::format( xml_meta ) - % m_kind - % xml::Escape(m_name) - ).str() ; - - http::StringResponse str ; - if ( post ) - http->Post( link, meta, &str, hdr ) ; - else - http->Put( link, meta, &str, hdr ) ; - - http::Header uphdr ; - uphdr.Add( "Expect:" ) ; - uphdr.Add( "Accept:" ) ; - - // the content upload URL is in the "Location" HTTP header - std::string uplink = http->RedirLocation() ; - http::XmlResponse xml ; - - http->Put( uplink, &file, &xml, uphdr ) ; - AssignIDs( Entry( xml.Response() ) ) ; - m_mtime = Entry(xml.Response()).MTime(); - + try { + File file( Path() ) ; + std::ostringstream xcontent_len ; + xcontent_len << "X-Upload-Content-Length: " << file.Size() ; + + http::Header hdr ; + hdr.Add( "Content-Type: application/atom+xml" ) ; + hdr.Add( "X-Upload-Content-Type: application/octet-stream" ) ; + hdr.Add( xcontent_len.str() ) ; + hdr.Add( "If-Match: " + m_etag ) ; + hdr.Add( "Expect:" ) ; + + std::string meta = (boost::format( xml_meta ) + % m_kind + % xml::Escape(m_name) + ).str() ; + + http::StringResponse str ; + if ( post ) + http->Post( link, meta, &str, hdr ) ; + else + http->Put( link, meta, &str, hdr ) ; + + http::Header uphdr ; + uphdr.Add( "Expect:" ) ; + uphdr.Add( "Accept:" ) ; + + // the content upload URL is in the "Location" HTTP header + std::string uplink = http->RedirLocation() ; + http::XmlResponse xml ; + + http->Put( uplink, &file, &xml, uphdr ) ; + AssignIDs( Entry( xml.Response() ) ) ; + m_mtime = Entry(xml.Response()).MTime(); + } + catch (gr::Exception& exc) + { + Log( "cannot upload: Exception %s", exc.what(), gr::log::critical) ; + return false; + } return true ; }