diff --git a/libgrive/src/drive/Drive.cc b/libgrive/src/drive/Drive.cc index 98f6833..84b1f55 100644 --- a/libgrive/src/drive/Drive.cc +++ b/libgrive/src/drive/Drive.cc @@ -183,7 +183,8 @@ std::cout << "local " << path << " is newer" << std::endl ; // re-reading the file ifile.seekg(0) ; - file.Upload( ifile.rdbuf(), m_http_hdr ) ; + if ( !file.Upload( ifile.rdbuf(), m_http_hdr ) ) +std::cout << path << " is read only" << std::endl ; } } } diff --git a/libgrive/src/drive/File.cc b/libgrive/src/drive/File.cc index 14cf37d..1b9e78e 100644 --- a/libgrive/src/drive/File.cc +++ b/libgrive/src/drive/File.cc @@ -56,8 +56,9 @@ void File::Update( const Json& entry ) FindInArray( "scheme", "http://schemas.google.com/g/2005#kind", node ) ? node["label"].Str() : std::string() ; - m_upload_link = entry["link"].FindInArray( "rel", - "http://schemas.google.com/g/2005#resumable-edit-media" )["href"].Str() ; + m_upload_link = entry["link"]. + FindInArray( "rel", "http://schemas.google.com/g/2005#resumable-edit-media", node ) + ? node["href"].Str() : std::string() ; // convert to lower case for easy comparison std::transform( @@ -115,8 +116,12 @@ void File::Download( const Path& file, const http::Headers& auth ) const os::SetFileTime( file, m_server_modified ) ; } -void File::Upload( std::streambuf *file, const http::Headers& auth ) +bool File::Upload( std::streambuf *file, const http::Headers& auth ) { + // upload link missing means that file is read only + if ( m_upload_link.empty() ) + return false ; + std::string meta = "\n" "" @@ -148,6 +153,7 @@ void File::Upload( std::streambuf *file, const http::Headers& auth ) uphdr.push_back( "Accept:" ) ; http.Put( http.RedirLocation(), data, uphdr ) ; + return true ; } } // end of namespace diff --git a/libgrive/src/drive/File.hh b/libgrive/src/drive/File.hh index 2727882..2346a29 100644 --- a/libgrive/src/drive/File.hh +++ b/libgrive/src/drive/File.hh @@ -48,7 +48,7 @@ public : std::string Parent() const ; void Download( const Path& file, const http::Headers& auth ) const ; - void Upload( std::streambuf *file, const http::Headers& auth ) ; + bool Upload( std::streambuf *file, const http::Headers& auth ) ; private : void Update( const Json& entry ) ;