diff --git a/libgrive/CMakeLists.txt b/libgrive/CMakeLists.txt index f3aa775..90ef451 100644 --- a/libgrive/CMakeLists.txt +++ b/libgrive/CMakeLists.txt @@ -14,6 +14,8 @@ find_package(ZLIB) find_package(PkgConfig) pkg_check_modules(YAJL REQUIRED yajl) +add_definitions(-Wall) + # additional headers if build unit tests IF ( CPPUNIT_FOUND ) set( OPT_INCS ${CPPUNIT_INCLUDE_DIR} ) diff --git a/libgrive/src/base/Resource.cc b/libgrive/src/base/Resource.cc index 7860516..9b75292 100644 --- a/libgrive/src/base/Resource.cc +++ b/libgrive/src/base/Resource.cc @@ -47,18 +47,18 @@ Resource::Resource( const fs::path& root_folder ) : m_kind ( "folder" ), m_id ( "folder:root" ), m_href ( "root" ), - m_parent ( 0 ), - m_state ( sync ), - m_is_editable( true ) + m_is_editable( true ), + m_parent ( NULL ), + m_state ( sync ) { } Resource::Resource( const std::string& name, const std::string& kind ) : m_name ( name ), m_kind ( kind ), - m_parent ( 0 ), - m_state ( unknown ), - m_is_editable( true ) + m_is_editable( true ), + m_parent ( NULL ), + m_state ( unknown ) { } diff --git a/libgrive/src/base/Resource.hh b/libgrive/src/base/Resource.hh index cb712c6..bc342a7 100644 --- a/libgrive/src/base/Resource.hh +++ b/libgrive/src/base/Resource.hh @@ -152,6 +152,7 @@ private : std::vector m_child ; State m_state ; + Val* m_json ; } ; } // end of namespace gr::v1 diff --git a/libgrive/src/base/State.cc b/libgrive/src/base/State.cc index fb64a47..c3f7cc2 100644 --- a/libgrive/src/base/State.cc +++ b/libgrive/src/base/State.cc @@ -342,51 +342,49 @@ void State::ChangeStamp( long cstamp ) bool State::Move( Syncer* syncer, fs::path old_p, fs::path new_p, fs::path grive_root ) { - //Convert paths to canonical representations - //Also seems to remove trailing / at the end of directory paths + // Convert paths to canonical representations + // Also seems to remove trailing / at the end of directory paths old_p = fs::canonical( old_p ); grive_root = fs::canonical( grive_root ); - //new_p is a little special because fs::canonical() requires that the path exists - if ( new_p.string()[ new_p.string().size() - 1 ] == '/') //If new_p ends with a /, remove it + // new_p is a little special because fs::canonical() requires that the path exists + if ( new_p.string()[ new_p.string().size() - 1 ] == '/') // If new_p ends with a /, remove it new_p = new_p.parent_path(); new_p = fs::canonical( new_p.parent_path() ) / new_p.filename(); - //Fails if source file doesn't exist, or if destination file already - //exists and is not a directory, or if the source and destination are exactly the same - if ( (fs::exists(new_p) && !fs::is_directory(new_p) ) || !fs::exists(old_p) || fs::equivalent( old_p, new_p ) ) + // Fails if source file doesn't exist, or if destination file already + // exists and is not a directory, or if the source and destination are exactly the same + if ( (fs::exists(new_p) && !fs::is_directory(new_p)) || !fs::exists(old_p) || fs::equivalent( old_p, new_p ) ) return false; - //If new path is an existing directory, move the file into the directory - //instead of trying to rename it - if ( fs::is_directory(new_p) ){ + // If new path is an existing directory, move the file into the directory + // instead of trying to rename it + if ( fs::is_directory( new_p ) ) new_p = new_p / old_p.filename(); - } - //Get the paths relative to grive root. - //Just finds the substring from the end of the grive_root to the end of the path - //+1s are to exclude slash at beginning of relative path - int start = grive_root.string().size() + 1; - int nLen = new_p.string().size() - (grive_root.string().size() + 1); - int oLen = old_p.string().size() - (grive_root.string().size() + 1); - if ( start + nLen != new_p.string().size() || start + oLen != old_p.string().size() ) + // Get the paths relative to grive root. + // Just finds the substring from the end of the grive_root to the end of the path + // +1s are to exclude slash at beginning of relative path + std::string root( grive_root.string() + "/" ); + if ( new_p.string().substr( 0, root.length() ).compare( root ) != 0 || + old_p.string().substr( 0, root.length() ).compare( root ) != 0 ) return false; - fs::path new_p_rootrel( new_p.string().substr( start, nLen ) ); - fs::path old_p_rootrel( old_p.string().substr( start, oLen ) ); + fs::path new_p_rootrel( new_p.string().substr( root.length() ) ); + fs::path old_p_rootrel( old_p.string().substr( root.length() ) ); //Get resources Resource* res = m_res.Root(); Resource* newParentRes = m_res.Root(); for ( fs::path::iterator it = old_p_rootrel.begin(); it != old_p_rootrel.end(); ++it ) { - if ( *it != "." && *it != ".." && res != 0 ) + if ( *it != "." && *it != ".." && res ) res = res->FindChild(it->string()); if ( *it == ".." ) res = res->Parent(); } for ( fs::path::iterator it = new_p_rootrel.begin(); it != new_p_rootrel.end(); ++it ) { - if ( *it != "." && *it != ".." && *it != new_p.filename() && newParentRes != 0 ) + if ( *it != "." && *it != ".." && *it != new_p.filename() && newParentRes ) newParentRes = newParentRes->FindChild(it->string()); if ( *it == "..") res = res->Parent(); diff --git a/libgrive/src/drive2/Syncer2.cc b/libgrive/src/drive2/Syncer2.cc index 3455181..5151279 100644 --- a/libgrive/src/drive2/Syncer2.cc +++ b/libgrive/src/drive2/Syncer2.cc @@ -121,11 +121,10 @@ bool Syncer2::Move( Resource* res, Resource* newParentRes, std::string newFilena http::Header hdr2 ; hdr2.Add( "Content-Type: application/json" ); http::ValResponse vrsp ; - long http_code = 0; //Don't change modified date because we're only moving - http_code = m_http->Put( feeds::files + "/" + res->ResourceID() + "?modifiedDateBehavior=noChange" + addRemoveParents, json_meta, &vrsp, hdr2 ) ; + long http_code = m_http->Put( feeds::files + "/" + res->ResourceID() + "?modifiedDateBehavior=noChange" + addRemoveParents, json_meta, &vrsp, hdr2 ) ; valr = vrsp.Response(); - assert( !( valr["id"].Str().empty() ) ); + assert( http_code == 200 && !( valr["id"].Str().empty() ) ); } return true; } @@ -167,7 +166,7 @@ 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( http_code == 200 && !( valr["id"].Str().empty() ) ); } else { diff --git a/libgrive/src/protocol/OAuth2.cc b/libgrive/src/protocol/OAuth2.cc index cd3dd6a..73ae088 100644 --- a/libgrive/src/protocol/OAuth2.cc +++ b/libgrive/src/protocol/OAuth2.cc @@ -37,8 +37,8 @@ OAuth2::OAuth2( const std::string& refresh_code, const std::string& client_id, const std::string& client_secret ) : - m_agent( agent ), m_refresh( refresh_code ), + m_agent( agent ), m_client_id( client_id ), m_client_secret( client_secret ) { diff --git a/libgrive/src/util/ConcatStream.cc b/libgrive/src/util/ConcatStream.cc index effec72..d93df5e 100644 --- a/libgrive/src/util/ConcatStream.cc +++ b/libgrive/src/util/ConcatStream.cc @@ -23,7 +23,7 @@ namespace gr { ConcatStream::ConcatStream() : - m_cur( 0 ), m_size( 0 ), m_pos( 0 ) + m_size( 0 ), m_pos( 0 ), m_cur( 0 ) { } @@ -63,13 +63,13 @@ off_t ConcatStream::Seek( off_t offset, int whence ) offset += m_pos; else if ( whence == 2 ) offset += Size(); - if ( offset > Size() ) + if ( (u64_t)offset > Size() ) offset = Size(); m_cur = 0; m_pos = offset; if ( m_streams.size() ) { - while ( offset > m_sizes[m_cur] ) + while ( (u64_t)offset > m_sizes[m_cur] ) m_cur++; m_streams[m_cur]->Seek( offset - ( m_cur > 0 ? m_sizes[m_cur-1] : 0 ), 0 ); } @@ -90,7 +90,7 @@ void ConcatStream::Append( SeekStream *stream ) { if ( stream ) { - off_t size = stream->Size(); + u64_t size = stream->Size(); if ( size > 0 ) { // "fix" stream size at the moment of adding so further changes of underlying files diff --git a/libgrive/src/util/ConcatStream.hh b/libgrive/src/util/ConcatStream.hh index 0ab037e..0966f06 100644 --- a/libgrive/src/util/ConcatStream.hh +++ b/libgrive/src/util/ConcatStream.hh @@ -41,9 +41,9 @@ public : private : std::vector m_streams ; - std::vector m_sizes ; - off_t m_size, m_pos ; - int m_cur ; + std::vector m_sizes ; + u64_t m_size, m_pos ; + size_t m_cur ; } ; } // end of namespace diff --git a/libgrive/src/util/StringStream.cc b/libgrive/src/util/StringStream.cc index a128f74..447f892 100644 --- a/libgrive/src/util/StringStream.cc +++ b/libgrive/src/util/StringStream.cc @@ -51,7 +51,7 @@ off_t StringStream::Seek( off_t offset, int whence ) offset += m_pos; else if ( whence == 2 ) offset += Size(); - if ( offset > Size() ) + if ( (u64_t)offset > Size() ) offset = Size(); m_pos = (size_t)offset; return m_pos;