From 32f62c08503b5cca1793816ffe4ca2db5f895162 Mon Sep 17 00:00:00 2001 From: Rafael Sadowski Date: Sun, 9 Oct 2016 10:54:35 +0200 Subject: [PATCH 01/83] fix: missing include under OpenBSD --- libgrive/src/util/File.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libgrive/src/util/File.cc b/libgrive/src/util/File.cc index 375cd625..93345aca 100644 --- a/libgrive/src/util/File.cc +++ b/libgrive/src/util/File.cc @@ -33,6 +33,10 @@ #include #include +#ifdef __OpenBSD__ +#include +#endif + #ifdef WIN32 #include typedef int ssize_t ; From 150a8176280b7c87a235998f0b4a98b33923148f Mon Sep 17 00:00:00 2001 From: Rafael Sadowski Date: Sun, 9 Oct 2016 11:00:12 +0200 Subject: [PATCH 02/83] fix: man(1) install directory unter OpenBSD --- grive/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/grive/CMakeLists.txt b/grive/CMakeLists.txt index 837a36d5..37145f10 100644 --- a/grive/CMakeLists.txt +++ b/grive/CMakeLists.txt @@ -26,4 +26,9 @@ set_target_properties( grive_executable ) install(TARGETS grive_executable RUNTIME DESTINATION bin) -install(FILES doc/grive.1 DESTINATION share/man/man1 ) + +if ( ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" ) + install(FILES doc/grive.1 DESTINATION man/man1 ) +else ( ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" ) + install(FILES doc/grive.1 DESTINATION share/man/man1 ) +endif( ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" ) From f8ea376769b6cc00f5993bba1eb97b2e0a484994 Mon Sep 17 00:00:00 2001 From: Albrecht Scheidig Date: Tue, 6 Dec 2016 23:28:28 +0100 Subject: [PATCH 03/83] Fix man page to reflect fix #58 "Make ignore regexp non-persistent (fix #58)" should be reflected in the man page. --- grive/doc/grive.1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/grive/doc/grive.1 b/grive/doc/grive.1 index cf0bc26d..47398352 100644 --- a/grive/doc/grive.1 +++ b/grive/doc/grive.1 @@ -48,7 +48,6 @@ Produces help message .TP \fB\-\-ignore\fR Ignore files with relative paths matching this Perl Regular Expression. -Value is remembered for next runs. .TP \fB\-l\fR , \fB\-\-log\fR Write log output to @@ -70,7 +69,7 @@ as the working copy root directory \fB\-s\fR , \fB\-\-dir\fR Sync a single .I -subdirectory. Internally converted to an ignore regexp, remembered for next runs. +subdirectory. Internally converted to an ignore regexp. .TP \fB\-v\fR, \fB\-\-version\fR Displays program version From bddf8cf6b0d9255c7d12a2d8453440bd64b552f3 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Sun, 19 Feb 2017 20:03:37 +0200 Subject: [PATCH 04/83] Add completion file for zsh. --- completion.zsh | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 completion.zsh diff --git a/completion.zsh b/completion.zsh new file mode 100644 index 00000000..4d3f8070 --- /dev/null +++ b/completion.zsh @@ -0,0 +1,63 @@ +#compdef grive +# ------------------------------------------------------------------------------ +# Copyright (c) 2015 Github zsh-users - http://github.com/zsh-users +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the zsh-users nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# ------------------------------------------------------------------------------ +# Description +# ----------- +# +# Completion script for Grive (https://github.com/vitalif/grive2) +# +# ------------------------------------------------------------------------------ +# Authors +# ------- +# +# * Doron Behar +# +# ------------------------------------------------------------------------------ +# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*- +# vim: ft=zsh sw=2 ts=2 et +# ------------------------------------------------------------------------------ + +local curcontext="$curcontext" state line ret=1 +typeset -A opt_args + +_arguments -C \ + '(-h --help)'{-h,--help}'[Produce help message]' \ + '(-v --version)'{-v,--version}'[Display Grive version]' \ + '(-a --auth)'{-a,--auth}'[Request authorization token]' \ + '(-p --path)'{-p,--path}'[Root directory to sync]' \ + '(-s --dir)'{-s,--dir}'[Single subdirectory to sync (remembered for next runs)]' \ + '(-V --verbose)'{-V,--verbose}'[Verbose mode. Enable more messages than normal.]' \ + '(--log-http)--log-http[Log all HTTP responses in this file for debugging.]' \ + '(--new-rev)--new-rev[Create,new revisions in server for updated files.]' \ + '(-d --debug)'{-d,--debug}'[Enable debug level messages. Implies -v.]' \ + '(-l --log)'{-l,--log}'[Set log output filename.]' \ + '(-f --force)'{-f,--force}'[Force grive to always download a file from Google Drive instead of uploading it.]' \ + '(--dry-run)--dry-run[Only,detect which files need to be uploaded/downloaded,without actually performing them.]' \ + '(--ignore)--ignore[Perl,RegExp to ignore files (matched against relative paths, remembered for next runs) ]' \ + '*: :_files' && ret=0 + +return ret From 974733ff462caa17690e74b214bdc78e512f13db Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 10 Mar 2017 13:33:40 +0100 Subject: [PATCH 05/83] also compile with cURL Version less than 7.32.0 --- libgrive/src/http/CurlAgent.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libgrive/src/http/CurlAgent.cc b/libgrive/src/http/CurlAgent.cc index eee9a8d9..8a9d43fc 100644 --- a/libgrive/src/http/CurlAgent.cc +++ b/libgrive/src/http/CurlAgent.cc @@ -190,8 +190,10 @@ long CurlAgent::ExecCurl( struct curl_slist *slist = SetHeader( m_pimpl->curl, hdr ) ; curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); - curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback); - curl_easy_setopt(curl, CURLOPT_XFERINFODATA, this); + #if LIBCURL_VERSION_NUM >= 0x072000 + curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback); + curl_easy_setopt(curl, CURLOPT_XFERINFODATA, this); + #endif CURLcode curl_code = ::curl_easy_perform(curl); From a0aff5b1462edacd364036c465fbbf32fc00f2c1 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 19 Mar 2017 12:48:01 +0300 Subject: [PATCH 06/83] Fix #136 - Skip links, sockets, fifos and etc --- libgrive/src/base/Resource.cc | 28 ++++++++++++++++++---------- libgrive/src/util/OS.cc | 12 ++++++------ libgrive/src/util/OS.hh | 6 ++++-- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/libgrive/src/base/Resource.cc b/libgrive/src/base/Resource.cc index 23ce335d..72c8052a 100644 --- a/libgrive/src/base/Resource.cc +++ b/libgrive/src/base/Resource.cc @@ -262,10 +262,10 @@ void Resource::FromLocal( Val& state ) if ( !IsRoot() ) { fs::path path = Path() ; - bool is_dir; + FileType ft ; try { - os::Stat( path, &m_ctime, (off64_t*)&m_size, &is_dir ) ; + os::Stat( path, &m_ctime, (off64_t*)&m_size, &ft ) ; } catch ( os::Error &e ) { @@ -276,22 +276,30 @@ void Resource::FromLocal( Val& state ) m_kind = "bad"; return; } + if ( ft == FT_UNKNOWN ) + { + // Skip sockets/FIFOs/etc + Log( "File %1% is not a regular file or directory; skipping file", path.string(), log::warning ); + m_state = sync; + m_kind = "bad"; + return; + } m_name = path.filename().string() ; - m_kind = is_dir ? "folder" : "file"; + m_kind = ft == FT_DIR ? "folder" : "file"; m_local_exists = true; bool is_changed; if ( state.Has( "ctime" ) && (u64_t) m_ctime.Sec() <= state["ctime"].U64() && - ( is_dir || state.Has( "md5" ) ) ) + ( ft == FT_DIR || state.Has( "md5" ) ) ) { - if ( !is_dir ) + if ( ft != FT_DIR ) m_md5 = state["md5"]; is_changed = false; } else { - if ( !is_dir ) + if ( ft != FT_DIR ) { // File is changed locally. TODO: Detect conflicts is_changed = ( state.Has( "size" ) && m_size != state["size"].U64() ) || @@ -703,13 +711,13 @@ void Resource::SetIndex( bool re_stat ) assert( m_parent && m_parent->m_json != NULL ); if ( !m_json ) m_json = &((*m_parent->m_json)["tree"]).Item( Name() ); - bool is_dir; + FileType ft; if ( re_stat ) - os::Stat( Path(), &m_ctime, NULL, &is_dir ); + os::Stat( Path(), &m_ctime, NULL, &ft ); else - is_dir = IsFolder(); + ft = IsFolder() ? FT_DIR : FT_FILE; m_json->Set( "ctime", Val( m_ctime.Sec() ) ); - if ( !is_dir ) + if ( ft != FT_DIR ) { m_json->Set( "md5", Val( m_md5 ) ); m_json->Set( "size", Val( m_size ) ); diff --git a/libgrive/src/util/OS.cc b/libgrive/src/util/OS.cc index 9095e730..e8b468fd 100644 --- a/libgrive/src/util/OS.cc +++ b/libgrive/src/util/OS.cc @@ -39,12 +39,12 @@ namespace gr { namespace os { -void Stat( const fs::path& filename, DateTime *t, off_t *size, bool *is_dir ) +void Stat( const fs::path& filename, DateTime *t, off_t *size, FileType *ft ) { - Stat( filename.string(), t, size, is_dir ) ; + Stat( filename.string(), t, size, ft ) ; } -void Stat( const std::string& filename, DateTime *t, off64_t *size, bool *is_dir ) +void Stat( const std::string& filename, DateTime *t, off64_t *size, FileType *ft ) { struct stat s = {} ; if ( ::stat( filename.c_str(), &s ) != 0 ) @@ -57,7 +57,7 @@ void Stat( const std::string& filename, DateTime *t, off64_t *size, bool *is_dir ) ; } - if (t) + if ( t ) { #if defined __APPLE__ && defined __DARWIN_64_BIT_INO_T *t = DateTime( s.st_ctimespec.tv_sec, s.st_ctimespec.tv_nsec ) ; @@ -67,8 +67,8 @@ void Stat( const std::string& filename, DateTime *t, off64_t *size, bool *is_dir } if ( size ) *size = s.st_size; - if ( is_dir ) - *is_dir = S_ISDIR( s.st_mode ) ? true : false; + if ( ft ) + *ft = S_ISDIR( s.st_mode ) ? FT_DIR : ( S_ISREG( s.st_mode ) ? FT_FILE : FT_UNKNOWN ) ; } void SetFileTime( const fs::path& filename, const DateTime& t ) diff --git a/libgrive/src/util/OS.hh b/libgrive/src/util/OS.hh index 43497839..bd28e30d 100644 --- a/libgrive/src/util/OS.hh +++ b/libgrive/src/util/OS.hh @@ -29,12 +29,14 @@ namespace gr { class DateTime ; class Path ; +enum FileType { FT_FILE = 1, FT_DIR = 2, FT_UNKNOWN = 3 } ; + namespace os { struct Error : virtual Exception {} ; - void Stat( const std::string& filename, DateTime *t, off64_t *size, bool *is_dir ) ; - void Stat( const fs::path& filename, DateTime *t, off64_t *size, bool *is_dir ) ; + void Stat( const std::string& filename, DateTime *t, off64_t *size, FileType *ft ) ; + void Stat( const fs::path& filename, DateTime *t, off64_t *size, FileType *ft ) ; void SetFileTime( const std::string& filename, const DateTime& t ) ; void SetFileTime( const fs::path& filename, const DateTime& t ) ; From 63bb138b2d8a23947479d3ac06eab4336abe40bc Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 19 Mar 2017 19:54:03 +0300 Subject: [PATCH 07/83] Fix #120, fix #125, fix #134 - Add .griveignore --- README.md | 19 +++++++ grive/doc/grive.1 | 35 +++++++++++-- grive/src/main.cc | 17 ++++-- libgrive/src/base/Drive.cc | 9 +--- libgrive/src/base/State.cc | 105 +++++++++++++++++++++++++++++++------ libgrive/src/base/State.hh | 8 +-- 6 files changed, 159 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 2e2ee468..51941c59 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ Grive uses cmake to build. Basic install sequence is ### Grive2 v0.5.1-dev +- support for .griveignore - no-remote-new and upload-only modes - ignore regexp does not persist anymore (note that Grive will still track it to not accidentally delete remote files when changing ignore regexp) @@ -137,3 +138,21 @@ New features: - #87: support for revisions - #86: ~~partial sync (contributed by justin at tierramedia.com)~~ that's not partial sync, that's only support for specifying local path on command line + +## .griveignore + +Rules are similar to Git's .gitignore, but may differ slightly due to the different +implementation. + +- lines that start with # are comments +- leading and trailing spaces ignored unless escaped with \ +- non-empty lines without ! in front are treated as "exclude" patterns +- non-empty lines with ! in front are treated as "include" patterns + and have a priority over all "exclude" ones +- patterns are matched against the filenames relative to the grive root +- a/**/b matches any number of subpaths between a and b, including 0 +- **/a matches `a` inside any directory +- b/** matches everything inside `b`, but not b itself +- \* matches any number of any characters except / +- ? matches any character except / +- .griveignore itself isn't ignored by default, but you can include it in itself to ignore diff --git a/grive/doc/grive.1 b/grive/doc/grive.1 index cf0bc26d..a00aef65 100644 --- a/grive/doc/grive.1 +++ b/grive/doc/grive.1 @@ -46,10 +46,6 @@ to download only files that are changed in Google Drive and already exist locall \fB\-h\fR, \fB\-\-help\fR Produces help message .TP -\fB\-\-ignore\fR -Ignore files with relative paths matching this Perl Regular Expression. -Value is remembered for next runs. -.TP \fB\-l\fR , \fB\-\-log\fR Write log output to .I @@ -81,6 +77,37 @@ Print ASCII progress bar for each downloaded/uploaded file. \fB\-V\fR, \fB\-\-verbose\fR Verbose mode. Enables more messages than usual. +.SH .griveignore +.PP +You may create .griveignore in your Grive root and use it to setup +exclusion/inclusion rules. +.PP +Rules are similar to Git's .gitignore, but may differ slightly due to the different +implementation. +.IP \[bu] +lines that start with # are comments +.IP \[bu] +leading and trailing spaces ignored unless escaped with \\ +.IP \[bu] +non-empty lines without ! in front are treated as "exclude" patterns +.IP \[bu] +non-empty lines with ! in front are treated as "include" patterns +and have a priority over all "exclude" ones +.IP \[bu] +patterns are matched against the filenames relative to the grive root +.IP \[bu] +a/**/b matches any number of subpaths between a and b, including 0 +.IP \[bu] +**/a matches `a` inside any directory +.IP \[bu] +b/** matches everything inside `b`, but not b itself +.IP \[bu] +* matches any number of any characters except / +.IP \[bu] +? matches any character except / +.IP \[bu] +\[char46]griveignore itself isn't ignored by default, but you can include it in itself to ignore + .SH AUTHORS .PP Current maintainer is Vitaliy Filippov. diff --git a/grive/src/main.cc b/grive/src/main.cc index c87a8543..b5a0a007 100644 --- a/grive/src/main.cc +++ b/grive/src/main.cc @@ -124,15 +124,22 @@ int Main( int argc, char **argv ) ( "no-remote-new,n", "Download only files that are changed in Google Drive and already exist locally" ) ( "dry-run", "Only detect which files need to be uploaded/downloaded, " "without actually performing them." ) - ( "ignore", po::value(), "Perl RegExp to ignore files (matched against relative paths)." ) ( "upload-speed,U", po::value(), "Limit upload speed in kbytes per second" ) ( "download-speed,D", po::value(), "Limit download speed in kbytes per second" ) ( "progress-bar,P", "Enable progress bar for upload/download of files") ; po::variables_map vm; - po::store(po::parse_command_line( argc, argv, desc), vm ); - po::notify(vm); + try + { + po::store( po::parse_command_line( argc, argv, desc ), vm ); + } + catch( po::error &e ) + { + std::cerr << "Options are incorrect. Use -h for help\n"; + return -1; + } + po::notify( vm ); // simple commands that doesn't require log or config if ( vm.count("help") ) @@ -148,9 +155,9 @@ int Main( int argc, char **argv ) } // initialize logging - InitLog(vm) ; + InitLog( vm ) ; - Config config(vm) ; + Config config( vm ) ; Log( "config file name %1%", config.Filename(), log::verbose ); diff --git a/libgrive/src/base/Drive.cc b/libgrive/src/base/Drive.cc index fd26225c..28fd29a1 100644 --- a/libgrive/src/base/Drive.cc +++ b/libgrive/src/base/Drive.cc @@ -41,15 +41,10 @@ namespace gr { -namespace -{ - const std::string state_file = ".grive_state" ; -} - Drive::Drive( Syncer *syncer, const Val& options ) : m_syncer ( syncer ), m_root ( options["path"].Str() ), - m_state ( m_root / state_file, options ), + m_state ( m_root, options ), m_options ( options ) { assert( m_syncer ) ; @@ -72,7 +67,7 @@ void Drive::FromChange( const Entry& entry ) void Drive::SaveState() { - m_state.Write( m_root / state_file ) ; + m_state.Write() ; } void Drive::DetectChanges() diff --git a/libgrive/src/base/State.cc b/libgrive/src/base/State.cc index 9fddf4d1..80e2a2dd 100644 --- a/libgrive/src/base/State.cc +++ b/libgrive/src/base/State.cc @@ -32,17 +32,28 @@ namespace gr { -State::State( const fs::path& filename, const Val& options ) : +const std::string state_file = ".grive_state" ; +const std::string ignore_file = ".griveignore" ; +const int MAX_IGN = 65536 ; +const char* regex_escape_chars = ".^$|()[]{}*+?\\"; +const boost::regex regex_escape_re( "[.^$|()\\[\\]{}*+?\\\\]" ); + +inline std::string regex_escape( std::string s ) +{ + return regex_replace( s, regex_escape_re, "\\\\&", boost::format_sed ); +} + +State::State( const fs::path& root, const Val& options ) : + m_root ( root ), m_res ( options["path"].Str() ), m_cstamp ( -1 ) { - Read( filename ) ; - + Read() ; + // the "-f" option will make grive always think remote is newer m_force = options.Has( "force" ) ? options["force"].Bool() : false ; - + std::string m_orig_ign = m_ign; - m_ign = ""; if ( options.Has( "ignore" ) && options["ignore"].Str() != m_ign ) m_ign = options["ignore"].Str(); else if ( options.Has( "dir" ) ) @@ -52,8 +63,7 @@ State::State( const fs::path& filename, const Val& options ) : if ( !m_dir.empty() ) { // "-s" is internally converted to an ignore regexp - const boost::regex esc( "[.^$|()\\[\\]{}*+?\\\\]" ); - m_dir = regex_replace( m_dir, esc, "\\\\&", boost::format_sed ); + m_dir = regex_escape( m_dir ); size_t pos = 0; while ( ( pos = m_dir.find( '/', pos ) ) != std::string::npos ) { @@ -66,7 +76,7 @@ State::State( const fs::path& filename, const Val& options ) : } m_ign_changed = m_orig_ign != "" && m_orig_ign != m_ign; - m_ign_re = boost::regex( m_ign.empty() ? "^\\.(grive|grive_state|trash)" : ( m_ign+"|^\\.(grive|grive_state|trash)" ) ); + m_ign_re = boost::regex( m_ign.empty() ? "^\\.(grive$|grive_state$|trash)" : ( m_ign+"|^\\.(grive|grive_state|trash)" ) ); } State::~State() @@ -277,27 +287,92 @@ State::iterator State::end() return m_res.end() ; } -void State::Read( const fs::path& filename ) +void State::Read() { try { - File file( filename ) ; - - m_st = ParseJson( file ); - m_ign = m_st.Has( "ignore_regexp" ) ? m_st["ignore_regexp"].Str() : std::string(); - + File st_file( m_root / state_file ) ; + m_st = ParseJson( st_file ); m_cstamp = m_st["change_stamp"].Int() ; } catch ( Exception& ) { } + + try + { + File ign_file( m_root / ignore_file ) ; + char ign[MAX_IGN] = { 0 }; + int s = ign_file.Read( ign, MAX_IGN-1 ) ; + ParseIgnoreFile( ign, s ); + } + catch ( Exception& e ) + { + throw e; + } +} + +bool State::ParseIgnoreFile( const char* buffer, int size ) +{ + const boost::regex re1( "/\\\\\\*\\\\\\*$" ); + const boost::regex re2( "^\\\\\\*\\\\\\*/" ); + const boost::regex re3( "([^\\\\](\\\\\\\\)*)/\\\\\\*\\\\\\*/" ); + const boost::regex re4( "([^\\\\](\\\\\\\\)*|^)\\\\\\*" ); + const boost::regex re5( "([^\\\\](\\\\\\\\)*|^)\\\\\\?" ); + std::string exclude_re, include_re; + int prev = 0; + for ( int i = 0; i <= size; i++ ) + { + if ( buffer[i] == '\n' || ( i == size && i > prev ) ) + { + while ( prev < i && ( buffer[prev] == ' ' || buffer[prev] == '\t' || buffer[prev] == '\r' ) ) + prev++; + if ( buffer[prev] != '#' ) + { + int j; + for ( j = i-1; j > prev; j-- ) + if ( buffer[j-1] == '\\' || ( buffer[j] != ' ' && buffer[j] != '\t' && buffer[j] != '\r' ) ) + break; + std::string str( buffer+prev, j+1-prev ); + bool inc = str[0] == '!'; + if ( inc ) + str = str.substr( 1 ); + str = regex_escape( str ); + str = regex_replace( str, re1, "/.*", boost::format_perl ); + str = regex_replace( str, re2, ".*/", boost::format_perl ); + str = regex_replace( str, re3, "$1/(.*/)*", boost::format_perl ); + str = regex_replace( str, re4, "$1[^/]*", boost::format_perl ); + std::string str1; + while (1) + { + str1 = regex_replace( str, re5, "$1[^/]", boost::format_perl ); + if ( str1.size() == str.size() ) + break; + str = str1; + } + if ( !inc ) + exclude_re = exclude_re + ( exclude_re.size() > 0 ? "|" : "" ) + str; + else + include_re = include_re + ( include_re.size() > 0 ? "|" : "" ) + str; + } + prev = i+1; + } + } + + if ( exclude_re.size() > 0 ) + { + m_ign = "^" + ( include_re.size() > 0 ? "(?!" + include_re + ")" : std::string() ) + "(" + exclude_re + ")$"; + return true; + } + return false; } -void State::Write( const fs::path& filename ) +void State::Write() { m_st.Set( "change_stamp", Val( m_cstamp ) ) ; m_st.Set( "ignore_regexp", Val( m_ign ) ) ; + fs::path filename = m_root / state_file ; std::ofstream fs( filename.string().c_str() ) ; fs << m_st ; } diff --git a/libgrive/src/base/State.hh b/libgrive/src/base/State.hh index 68b6df88..b42a32e7 100644 --- a/libgrive/src/base/State.hh +++ b/libgrive/src/base/State.hh @@ -42,15 +42,15 @@ public : typedef ResourceTree::iterator iterator ; public : - explicit State( const fs::path& filename, const Val& options ) ; + explicit State( const fs::path& root, const Val& options ) ; ~State() ; void FromLocal( const fs::path& p ) ; void FromRemote( const Entry& e ) ; void ResolveEntry() ; - void Read( const fs::path& filename ) ; - void Write( const fs::path& filename ) ; + void Read() ; + void Write() ; Resource* FindByHref( const std::string& href ) ; Resource* FindByID( const std::string& id ) ; @@ -64,6 +64,7 @@ public : void ChangeStamp( long cstamp ) ; private : + bool ParseIgnoreFile( const char* buffer, int size ) ; void FromLocal( const fs::path& p, Resource *folder, Val& tree ) ; void FromChange( const Entry& e ) ; bool Update( const Entry& e ) ; @@ -72,6 +73,7 @@ private : bool IsIgnore( const std::string& filename ) ; private : + fs::path m_root ; ResourceTree m_res ; int m_cstamp ; std::string m_ign ; From 4b6cf69cbb5bc9a47beb34f5204c92d76c558158 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Wed, 22 Mar 2017 18:28:48 +0300 Subject: [PATCH 08/83] Fix #139 --- libgrive/src/base/State.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/libgrive/src/base/State.cc b/libgrive/src/base/State.cc index 80e2a2dd..6d86a92b 100644 --- a/libgrive/src/base/State.cc +++ b/libgrive/src/base/State.cc @@ -308,7 +308,6 @@ void State::Read() } catch ( Exception& e ) { - throw e; } } From d996989c29a223af5a9d6e1dd42788c19815b9f7 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Mon, 24 Apr 2017 23:58:37 +0200 Subject: [PATCH 09/83] Add user systemd units The units can be used to automatically sync a folder in the users home dir * every 3 minutes * on local file changes (requires inotify-tools). To enable the units for `~/google-drive/`: ``` systemctl --user enable grive-timer@google-drive.timer systemctl --user start grive-timer@google-drive.timer systemctl --user enable grive-changes@google-drive.service systemctl --user start grive-changes@google-drive.service ``` The units can be enabled multiple times --- CMakeLists.txt | 4 + systemd/CMakeLists.txt | 26 +++++++ systemd/grive-changes@.service.in | 11 +++ systemd/grive-sync.sh | 118 ++++++++++++++++++++++++++++++ systemd/grive-timer@.service.in | 6 ++ systemd/grive-timer@.timer | 11 +++ 6 files changed, 176 insertions(+) create mode 100644 systemd/CMakeLists.txt create mode 100644 systemd/grive-changes@.service.in create mode 100755 systemd/grive-sync.sh create mode 100644 systemd/grive-timer@.service.in create mode 100644 systemd/grive-timer@.timer diff --git a/CMakeLists.txt b/CMakeLists.txt index 95443aa7..951d8749 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 2.8) +include(GNUInstallDirs) + # Grive version. remember to update it for every new release! set( GRIVE_VERSION "0.5.1-dev" ) @@ -7,5 +9,7 @@ set( GRIVE_VERSION "0.5.1-dev" ) add_definitions( -DVERSION="${GRIVE_VERSION}" ) add_definitions( -D_FILE_OFFSET_BITS=64 -std=c++0x ) +add_subdirectory( systemd ) add_subdirectory( libgrive ) add_subdirectory( grive ) + \ No newline at end of file diff --git a/systemd/CMakeLists.txt b/systemd/CMakeLists.txt new file mode 100644 index 00000000..e3e57baf --- /dev/null +++ b/systemd/CMakeLists.txt @@ -0,0 +1,26 @@ +SET(GRIVE_SYNC_SH_BINARY "${CMAKE_INSTALL_PREFIX}/lib/grive/grive-sync.sh") + +CONFIGURE_FILE(grive-changes@.service.in grive-changes@.service @ONLY) +CONFIGURE_FILE(grive-timer@.service.in grive-timer@.service @ONLY) + +install( + FILES + ${CMAKE_BINARY_DIR}/systemd/grive-changes@.service + ${CMAKE_BINARY_DIR}/systemd/grive-timer@.service + DESTINATION + lib/systemd/user +) + +install( + FILES + grive-timer@.timer + DESTINATION + lib/systemd/user +) + +install( + PROGRAMS + grive-sync.sh + DESTINATION + lib/grive +) \ No newline at end of file diff --git a/systemd/grive-changes@.service.in b/systemd/grive-changes@.service.in new file mode 100644 index 00000000..172ab197 --- /dev/null +++ b/systemd/grive-changes@.service.in @@ -0,0 +1,11 @@ +[Unit] +Description=Google drive sync (changed files) + +[Service] +ExecStart=@GRIVE_SYNC_SH_BINARY@ listen "%i" +Type=simple +Restart=always +RestartSec=30 + +[Install] +WantedBy=default.target diff --git a/systemd/grive-sync.sh b/systemd/grive-sync.sh new file mode 100755 index 00000000..f070ac0c --- /dev/null +++ b/systemd/grive-sync.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +# Copyright (C) 2009 Przemyslaw Pawelczyk +# (C) 2017 Jan Schulz +## +## This script is licensed under the terms of the MIT license. +## https://opensource.org/licenses/MIT + +# Fail on all errors +set -o pipefail + +# We always start in the current users home directory so that names always start there +cd ~ + + +### ARGUMENT PARSING ### +SCRIPT=${0} + +if [[ -z ${2} ]] || [[ ! -d ${2} ]] ; then + echo "Need a directory name in the current users home directory as second argument. Aborting." + exit 1 +fi + +DIRECTORY=$2 + +if [[ -z ${1} ]] ; then + echo "Need a command as first argument. Aborting." + exit 1 +else + if [[ "sync" == "${1}" ]] ; then + COMMAND=sync + elif [[ "listen" == "${1}" ]] ; then + COMMAND=listen + else + echo "Unknown command. Aborting." + exit 1 + fi +fi + + +### LOCKFILE BOILERPLATE ### +LOCKFILE="/run/user/$(id -u)/$(basename $0)_${DIRECTORY//\//_}" +LOCKFD=99 + +# PRIVATE +_lock() { flock -$1 $LOCKFD; } +_no_more_locking() { _lock u; _lock xn && rm -f $LOCKFILE; } +_prepare_locking() { eval "exec $LOCKFD>\"$LOCKFILE\""; trap _no_more_locking EXIT; } + +# ON START +_prepare_locking + +# PUBLIC +exlock_now() { _lock xn; } # obtain an exclusive lock immediately or fail +exlock() { _lock x; } # obtain an exclusive lock +shlock() { _lock s; } # obtain a shared lock +unlock() { _lock u; } # drop a lock + +### SYNC SCRIPT ### +# Idea: only let one script run, but if the sync script is called a second time +# make sure we sync a second time, too + +sync_directory() { + _directory=${1} + if ping -c1 -W1 -q accounts.google.com >/dev/null 2>&1; then + true + # pass + else + echo "Google drive server not reachable..." + exit 0 + fi + + reset_timer_and_exit() { echo "Retriggered google drive sync" && touch -m $LOCKFILE && exit; } + + exlock_now || reset_timer_and_exit + + TIME_AT_START=0 + TIME_AT_END=1 + while [[ ${TIME_AT_START} -lt ${TIME_AT_END} ]]; do + echo "Syncing ${_directory}..." + TIME_AT_START=$(stat -c %Y $LOCKFILE) + grive -p ${_directory} 2>&1 | grep -v -E "^Reading local directories$|^Reading remote server file list$|^Synchronizing files$|^Finished!$" + TIME_AT_END=$(stat -c %Y $LOCKFILE) + echo "Sync of ${_directory} done." + done + + # always exit ok, so that we never go into a wrong systemd state + exit 0 +} + +### LISTEN TO DIRECTORY CHANGES ### + + +listen_directory() { + _directory=${1} + + type inotifywait >/dev/null 2>&1 || { echo >&2 "I require inotifywait but it's not installed. Aborting."; exit 1; } + + echo "Listening for changes in ~/${_directory}" + + while true #run indefinitely + do + # Use a different call to not need to change exit into return + inotifywait -q -r -e modify,attrib,close_write,move,create,delete --exclude ".grive_state|.grive" ${_directory} > /dev/null 2>&1 && ${SCRIPT} sync ${_directory} + done + + # always exit ok, so that we never go into a wrong systemd state + exit 0 +} + +if [[ ${COMMAND} == listen ]] ; then + listen_directory ${DIRECTORY} +else + sync_directory ${DIRECTORY} +fi + +# always exit ok, so that we never go into a wrong systemd state +exit 0 \ No newline at end of file diff --git a/systemd/grive-timer@.service.in b/systemd/grive-timer@.service.in new file mode 100644 index 00000000..a6aae6ab --- /dev/null +++ b/systemd/grive-timer@.service.in @@ -0,0 +1,6 @@ +[Unit] +Description=Google drive sync +After=network-online.target + +[Service] +ExecStart=@GRIVE_SYNC_SH_BINARY@ sync "%i" diff --git a/systemd/grive-timer@.timer b/systemd/grive-timer@.timer new file mode 100644 index 00000000..32f14b9a --- /dev/null +++ b/systemd/grive-timer@.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Google drive sync (fixed intervals) + +[Timer] +OnCalendar=*:0/5 +OnBootSec=3min +OnUnitActiveSec=5min +Unit=grive-timer@%i.service + +[Install] +WantedBy=timers.target From 4fe1e71d5b1bc121c67dd5a99faa4600a6a4a64a Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Mon, 5 Jun 2017 14:18:13 +0300 Subject: [PATCH 10/83] Issue #148 - add debug message for the case --- libgrive/src/base/State.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libgrive/src/base/State.cc b/libgrive/src/base/State.cc index 6d86a92b..6cbf984f 100644 --- a/libgrive/src/base/State.cc +++ b/libgrive/src/base/State.cc @@ -235,6 +235,12 @@ bool State::Update( const Entry& e ) } else if ( Resource *parent = m_res.FindByHref( e.ParentHref() ) ) { + if ( !parent->IsFolder() ) + { + // https://github.com/vitalif/grive2/issues/148 + Log( "%1% is owned by something that's not a directory: href=%2% name=%3%", e.Name(), e.ParentHref(), parent->RelPath(), log::error ); + return true; + } assert( parent->IsFolder() ) ; std::string path = parent->IsRoot() ? e.Name() : ( parent->RelPath() / e.Name() ).string(); From 90c603dc4c15657fb1fc2d7f3ed9d6e9170d8320 Mon Sep 17 00:00:00 2001 From: Mitos Kalandiel Date: Fri, 11 Aug 2017 12:05:53 +0100 Subject: [PATCH 11/83] added 3 more dependencies on linux mint 18.3 I also had to install "debhelper", "zlib1g-dev" & "dpkg-dev" to be able to run the dpkg-buildpackage command --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 51941c59..ace7f571 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,8 @@ On a Debian/Ubuntu/Linux Mint machine just run the following command to install these packages: sudo apt-get install git cmake build-essential libgcrypt11-dev libyajl-dev \ - libboost-all-dev libcurl4-openssl-dev libexpat1-dev libcppunit-dev binutils-dev + libboost-all-dev libcurl4-openssl-dev libexpat1-dev libcppunit-dev binutils-dev \ + debhelper zlib1g-dev dpkg-dev FreeBSD: From 31b5ab59fcd6d049a7ccbc7ef147707d9d497997 Mon Sep 17 00:00:00 2001 From: Daniel Deptford Date: Fri, 13 Oct 2017 22:25:51 -0700 Subject: [PATCH 12/83] Adding command-line options to specify authentication id and secret. On branch custom-id-secret Changes to be committed: modified: grive/src/main.cc --- grive/src/main.cc | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/grive/src/main.cc b/grive/src/main.cc index b5a0a007..7f0bd33c 100644 --- a/grive/src/main.cc +++ b/grive/src/main.cc @@ -46,8 +46,8 @@ #include #include -const std::string client_id = "22314510474.apps.googleusercontent.com" ; -const std::string client_secret = "bl4ufi89h-9MkFlypcI7R785" ; +const std::string default_id = "22314510474.apps.googleusercontent.com" ; +const std::string default_secret = "bl4ufi89h-9MkFlypcI7R785" ; using namespace gr ; namespace po = boost::program_options; @@ -111,6 +111,8 @@ int Main( int argc, char **argv ) ( "help,h", "Produce help message" ) ( "version,v", "Display Grive version" ) ( "auth,a", "Request authorization token" ) + ( "id,i", po::value(), "Authentication ID") + ( "secret,e", po::value(), "Authentication secret") ( "path,p", po::value(), "Path to working copy root") ( "dir,s", po::value(), "Single subdirectory to sync") ( "verbose,V", "Verbose mode. Enable more messages than normal.") @@ -172,9 +174,22 @@ int Main( int argc, char **argv ) http->SetProgressReporter( pb.get() ); } + std::string id = default_id; + std::string secret = default_secret; + + if( vm.count( "id" ) ) + { + id = vm["id"].as(); + } + + if( vm.count( "secret" ) ) + { + secret = vm["secret"].as(); + } + if ( vm.count( "auth" ) ) { - OAuth2 token( http.get(), client_id, client_secret ) ; + OAuth2 token( http.get(), id, secret ) ; std::cout << "-----------------------\n" @@ -210,7 +225,7 @@ int Main( int argc, char **argv ) return -1; } - OAuth2 token( http.get(), refresh_token, client_id, client_secret ) ; + OAuth2 token( http.get(), refresh_token, id, secret ) ; AuthAgent agent( token, http.get() ) ; v2::Syncer2 syncer( &agent ); From 81a7c34c22cdc3d3ad4590f065f3507adab4bbcb Mon Sep 17 00:00:00 2001 From: Vasilis Date: Tue, 7 Nov 2017 17:39:13 +0100 Subject: [PATCH 13/83] Added libstdc++-7-dev in the Build-Depends for Ubuntu 17.10 --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index edad2557..bd66c5f7 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: grive2 Section: net Priority: optional Maintainer: Vitaliy Filippov -Build-Depends: debhelper, cmake, pkg-config, zlib1g-dev, libcurl4-openssl-dev | libcurl4-gnutls-dev, libstdc++-6-dev | libstdc++6-4.4-dev | libstdc++-4.9-dev | libstdc++-5-dev, libboost-filesystem-dev, libboost-program-options-dev, libboost-test-dev, libboost-regex-dev, libexpat1-dev, binutils-dev, libgcrypt-dev, libyajl-dev +Build-Depends: debhelper, cmake, pkg-config, zlib1g-dev, libcurl4-openssl-dev | libcurl4-gnutls-dev, libstdc++-7-dev |libstdc++-6-dev | libstdc++6-4.4-dev | libstdc++-4.9-dev | libstdc++-5-dev, libboost-filesystem-dev, libboost-program-options-dev, libboost-test-dev, libboost-regex-dev, libexpat1-dev, binutils-dev, libgcrypt-dev, libyajl-dev Standards-Version: 3.9.6 Homepage: https://yourcmc.ru/wiki/Grive2 From 4e5c61b668781043668d688519af3bb5c98bf9e7 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Tue, 21 Nov 2017 22:34:46 +0300 Subject: [PATCH 14/83] Add pkg-config (fixes #126) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ace7f571..2b26772e 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ these packages: sudo apt-get install git cmake build-essential libgcrypt11-dev libyajl-dev \ libboost-all-dev libcurl4-openssl-dev libexpat1-dev libcppunit-dev binutils-dev \ - debhelper zlib1g-dev dpkg-dev + debhelper zlib1g-dev dpkg-dev pkg-config FreeBSD: From 70c5c64373120f6cd8ddff64342418c075f64a82 Mon Sep 17 00:00:00 2001 From: psfloyd Date: Fri, 1 Dec 2017 00:12:14 -0300 Subject: [PATCH 15/83] Fix for service files and script to work with directories with spaces in their names --- systemd/grive-changes@.service.in | 2 +- systemd/grive-sync.sh | 47 ++++++++++++++++--------------- systemd/grive-timer@.service.in | 2 +- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/systemd/grive-changes@.service.in b/systemd/grive-changes@.service.in index 172ab197..6b3ca291 100644 --- a/systemd/grive-changes@.service.in +++ b/systemd/grive-changes@.service.in @@ -2,7 +2,7 @@ Description=Google drive sync (changed files) [Service] -ExecStart=@GRIVE_SYNC_SH_BINARY@ listen "%i" +ExecStart=@GRIVE_SYNC_SH_BINARY@ listen "%I" Type=simple Restart=always RestartSec=30 diff --git a/systemd/grive-sync.sh b/systemd/grive-sync.sh index f070ac0c..13cacfe5 100755 --- a/systemd/grive-sync.sh +++ b/systemd/grive-sync.sh @@ -14,16 +14,16 @@ cd ~ ### ARGUMENT PARSING ### -SCRIPT=${0} +SCRIPT="${0}" -if [[ -z ${2} ]] || [[ ! -d ${2} ]] ; then +if [[ -z "${2}" ]] || [[ ! -d "${2}" ]] ; then echo "Need a directory name in the current users home directory as second argument. Aborting." exit 1 fi -DIRECTORY=$2 +DIRECTORY="$2" -if [[ -z ${1} ]] ; then +if [[ -z "${1}" ]] ; then echo "Need a command as first argument. Aborting." exit 1 else @@ -39,13 +39,13 @@ fi ### LOCKFILE BOILERPLATE ### -LOCKFILE="/run/user/$(id -u)/$(basename $0)_${DIRECTORY//\//_}" +LOCKFILE="/run/user/"$(id -u)"/"$(basename "$0")"_"${DIRECTORY//\//_}"" LOCKFD=99 # PRIVATE -_lock() { flock -$1 $LOCKFD; } -_no_more_locking() { _lock u; _lock xn && rm -f $LOCKFILE; } -_prepare_locking() { eval "exec $LOCKFD>\"$LOCKFILE\""; trap _no_more_locking EXIT; } +_lock() { flock -"$1" "$LOCKFD"; } +_no_more_locking() { _lock u; _lock xn && rm -f "$LOCKFILE"; } +_prepare_locking() { eval "exec "$LOCKFD">\""$LOCKFILE"\""; trap _no_more_locking EXIT; } # ON START _prepare_locking @@ -61,7 +61,7 @@ unlock() { _lock u; } # drop a lock # make sure we sync a second time, too sync_directory() { - _directory=${1} + _directory="${1}" if ping -c1 -W1 -q accounts.google.com >/dev/null 2>&1; then true # pass @@ -70,18 +70,18 @@ sync_directory() { exit 0 fi - reset_timer_and_exit() { echo "Retriggered google drive sync" && touch -m $LOCKFILE && exit; } + reset_timer_and_exit() { echo "Retriggered google drive sync" && touch -m "$LOCKFILE" && exit; } exlock_now || reset_timer_and_exit TIME_AT_START=0 TIME_AT_END=1 - while [[ ${TIME_AT_START} -lt ${TIME_AT_END} ]]; do - echo "Syncing ${_directory}..." - TIME_AT_START=$(stat -c %Y $LOCKFILE) - grive -p ${_directory} 2>&1 | grep -v -E "^Reading local directories$|^Reading remote server file list$|^Synchronizing files$|^Finished!$" - TIME_AT_END=$(stat -c %Y $LOCKFILE) - echo "Sync of ${_directory} done." + while [[ "${TIME_AT_START}" -lt "${TIME_AT_END}" ]]; do + echo "Syncing "${_directory}"..." + TIME_AT_START="$(stat -c %Y "$LOCKFILE")" + grive -p "${_directory}" 2>&1 | grep -v -E "^Reading local directories$|^Reading remote server file list$|^Synchronizing files$|^Finished!$" + TIME_AT_END="$(stat -c %Y "$LOCKFILE")" + echo "Sync of "${_directory}" done." done # always exit ok, so that we never go into a wrong systemd state @@ -92,27 +92,28 @@ sync_directory() { listen_directory() { - _directory=${1} + _directory="${1}" type inotifywait >/dev/null 2>&1 || { echo >&2 "I require inotifywait but it's not installed. Aborting."; exit 1; } - echo "Listening for changes in ~/${_directory}" + echo "Listening for changes in ~/"${_directory}"" while true #run indefinitely do # Use a different call to not need to change exit into return - inotifywait -q -r -e modify,attrib,close_write,move,create,delete --exclude ".grive_state|.grive" ${_directory} > /dev/null 2>&1 && ${SCRIPT} sync ${_directory} + inotifywait -q -r -e modify,attrib,close_write,move,create,delete --exclude ".grive_state|.grive" "${_directory}" > /dev/null 2>&1 && ${SCRIPT} sync "${_directory}" + #echo ${SCRIPT} "${_directory}" done # always exit ok, so that we never go into a wrong systemd state exit 0 } -if [[ ${COMMAND} == listen ]] ; then - listen_directory ${DIRECTORY} +if [[ "${COMMAND}" == listen ]] ; then + listen_directory "${DIRECTORY}" else - sync_directory ${DIRECTORY} + sync_directory "${DIRECTORY}" fi # always exit ok, so that we never go into a wrong systemd state -exit 0 \ No newline at end of file +exit 0 diff --git a/systemd/grive-timer@.service.in b/systemd/grive-timer@.service.in index a6aae6ab..56ae8b3a 100644 --- a/systemd/grive-timer@.service.in +++ b/systemd/grive-timer@.service.in @@ -3,4 +3,4 @@ Description=Google drive sync After=network-online.target [Service] -ExecStart=@GRIVE_SYNC_SH_BINARY@ sync "%i" +ExecStart=@GRIVE_SYNC_SH_BINARY@ sync "%I" From 94bda77b1bd20d6a9086537469400dbc1737642a Mon Sep 17 00:00:00 2001 From: psfloyd Date: Mon, 4 Dec 2017 02:33:53 -0300 Subject: [PATCH 16/83] Removed debug line --- systemd/grive-sync.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/systemd/grive-sync.sh b/systemd/grive-sync.sh index 13cacfe5..0a7aad30 100755 --- a/systemd/grive-sync.sh +++ b/systemd/grive-sync.sh @@ -102,7 +102,6 @@ listen_directory() { do # Use a different call to not need to change exit into return inotifywait -q -r -e modify,attrib,close_write,move,create,delete --exclude ".grive_state|.grive" "${_directory}" > /dev/null 2>&1 && ${SCRIPT} sync "${_directory}" - #echo ${SCRIPT} "${_directory}" done # always exit ok, so that we never go into a wrong systemd state From d698d596d91ffb0acb07fd6faae3c410475a09e1 Mon Sep 17 00:00:00 2001 From: psfloyd Date: Fri, 8 Dec 2017 00:23:17 -0300 Subject: [PATCH 17/83] Can enable services systemd excaped --- systemd/grive-changes@.service.in | 2 +- systemd/grive-sync.sh | 5 +++-- systemd/grive-timer@.service.in | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/systemd/grive-changes@.service.in b/systemd/grive-changes@.service.in index 6b3ca291..172ab197 100644 --- a/systemd/grive-changes@.service.in +++ b/systemd/grive-changes@.service.in @@ -2,7 +2,7 @@ Description=Google drive sync (changed files) [Service] -ExecStart=@GRIVE_SYNC_SH_BINARY@ listen "%I" +ExecStart=@GRIVE_SYNC_SH_BINARY@ listen "%i" Type=simple Restart=always RestartSec=30 diff --git a/systemd/grive-sync.sh b/systemd/grive-sync.sh index 0a7aad30..36ef2e17 100755 --- a/systemd/grive-sync.sh +++ b/systemd/grive-sync.sh @@ -15,13 +15,13 @@ cd ~ ### ARGUMENT PARSING ### SCRIPT="${0}" +DIRECTORY=$(systemd-escape --unescape "$2") -if [[ -z "${2}" ]] || [[ ! -d "${2}" ]] ; then +if [[ -z "$DIRECTORY" ]] || [[ ! -d "$DIRECTORY" ]] ; then echo "Need a directory name in the current users home directory as second argument. Aborting." exit 1 fi -DIRECTORY="$2" if [[ -z "${1}" ]] ; then echo "Need a command as first argument. Aborting." @@ -102,6 +102,7 @@ listen_directory() { do # Use a different call to not need to change exit into return inotifywait -q -r -e modify,attrib,close_write,move,create,delete --exclude ".grive_state|.grive" "${_directory}" > /dev/null 2>&1 && ${SCRIPT} sync "${_directory}" + #echo ${SCRIPT} "${_directory}" done # always exit ok, so that we never go into a wrong systemd state diff --git a/systemd/grive-timer@.service.in b/systemd/grive-timer@.service.in index 56ae8b3a..a6aae6ab 100644 --- a/systemd/grive-timer@.service.in +++ b/systemd/grive-timer@.service.in @@ -3,4 +3,4 @@ Description=Google drive sync After=network-online.target [Service] -ExecStart=@GRIVE_SYNC_SH_BINARY@ sync "%I" +ExecStart=@GRIVE_SYNC_SH_BINARY@ sync "%i" From 2e75fc669b5ac0162153b108f97095eb4beb1bb2 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Tue, 2 Jan 2018 16:26:36 -0800 Subject: [PATCH 18/83] Fix uninitialized use of c2 variable in State::FromLocal --- libgrive/src/base/State.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libgrive/src/base/State.cc b/libgrive/src/base/State.cc index 6cbf984f..0121343a 100644 --- a/libgrive/src/base/State.cc +++ b/libgrive/src/base/State.cc @@ -140,7 +140,7 @@ void State::FromLocal( const fs::path& p, Resource* folder, Val& tree ) else { // Restore state of locally deleted files - Resource *c = folder->FindChild( i->first ), *c2 ; + Resource *c = folder->FindChild( i->first ), *c2 = c ; if ( !c ) { c2 = new Resource( i->first, i->second.Has( "tree" ) ? "folder" : "file" ) ; From 8f2f217da644c0d0560fecd65597c18e83fbef71 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Tue, 2 Jan 2018 18:07:45 -0800 Subject: [PATCH 19/83] Link against specific Boost libraries, avoid using Boost_LIBRARIES grive should not be linked against the Boost unit test framework, only btest needs it. Don't specify Boost libraries for executables if libgrive uses those libraries. CMake takes care of the dependencies. --- grive/CMakeLists.txt | 1 - libgrive/CMakeLists.txt | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/grive/CMakeLists.txt b/grive/CMakeLists.txt index 37145f10..a01d3b56 100644 --- a/grive/CMakeLists.txt +++ b/grive/CMakeLists.txt @@ -17,7 +17,6 @@ add_executable( grive_executable ) target_link_libraries( grive_executable - ${Boost_LIBRARIES} grive ) diff --git a/libgrive/CMakeLists.txt b/libgrive/CMakeLists.txt index 54776bd1..73600d11 100644 --- a/libgrive/CMakeLists.txt +++ b/libgrive/CMakeLists.txt @@ -83,7 +83,10 @@ target_link_libraries( grive ${YAJL_LIBRARIES} ${CURL_LIBRARIES} ${LIBGCRYPT_LIBRARIES} - ${Boost_LIBRARIES} + ${Boost_FILESYSTEM_LIBRARY} + ${Boost_PROGRAM_OPTIONS_LIBRARY} + ${Boost_REGEX_LIBRARY} + ${Boost_SYSTEM_LIBRARY} ${IBERTY_LIBRARY} ${EXPAT_LIBRARY} ${OPT_LIBS} @@ -126,7 +129,6 @@ IF ( CPPUNIT_FOUND ) target_link_libraries( unittest grive ${CPPUNIT_LIBRARY} - ${Boost_LIBRARIES} ) ENDIF ( CPPUNIT_FOUND ) @@ -139,7 +141,7 @@ add_executable( btest ${BTEST_SRC} ) target_link_libraries( btest grive - ${Boost_LIBRARIES} + ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ) if ( WIN32 ) From bff462211a49236ea8adda6c65f85baa478f2caa Mon Sep 17 00:00:00 2001 From: Carlos J Date: Mon, 15 Jan 2018 21:59:17 +0100 Subject: [PATCH 20/83] FreeBSD fixes and improvements --- grive/CMakeLists.txt | 6 +++--- libgrive/src/util/File.cc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/grive/CMakeLists.txt b/grive/CMakeLists.txt index 37145f10..32dd16b9 100644 --- a/grive/CMakeLists.txt +++ b/grive/CMakeLists.txt @@ -27,8 +27,8 @@ set_target_properties( grive_executable install(TARGETS grive_executable RUNTIME DESTINATION bin) -if ( ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" ) +if ( ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" ) install(FILES doc/grive.1 DESTINATION man/man1 ) -else ( ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" ) +else ( ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" ) install(FILES doc/grive.1 DESTINATION share/man/man1 ) -endif( ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" ) +endif( ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD" ) diff --git a/libgrive/src/util/File.cc b/libgrive/src/util/File.cc index 93345aca..c5184ecd 100644 --- a/libgrive/src/util/File.cc +++ b/libgrive/src/util/File.cc @@ -33,7 +33,7 @@ #include #include -#ifdef __OpenBSD__ +#if defined(__FreeBSD__) || defined(__OpenBSD__) #include #endif From b06f66c86dda6df035c06b3b0486bf0211698e1c Mon Sep 17 00:00:00 2001 From: Carlos J Date: Mon, 15 Jan 2018 23:43:15 +0100 Subject: [PATCH 21/83] Unbreak the build against new Clang version 6.0.0 --- libgrive/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libgrive/CMakeLists.txt b/libgrive/CMakeLists.txt index 54776bd1..3b48e3c6 100644 --- a/libgrive/CMakeLists.txt +++ b/libgrive/CMakeLists.txt @@ -142,6 +142,10 @@ target_link_libraries( btest ${Boost_LIBRARIES} ) +if ( ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" ) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++11-narrowing" ) +endif ( ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" ) + if ( WIN32 ) else ( WIN32 ) set_target_properties( btest From cdea48edc13933bd1ba7ce571ee58e46e701927f Mon Sep 17 00:00:00 2001 From: Jan Katins Date: Thu, 20 Apr 2017 13:15:29 +0200 Subject: [PATCH 22/83] gitignore: ignore files produced by the deb build --- .gitignore | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index 6fa3768d..b33b2e27 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,12 @@ bgrive/bgrive grive/grive libgrive/btest *.cmake + +debian/debhelper-build-stamp +debian/files +debian/grive.debhelper.log +debian/grive.substvars +debian/grive/ +debian/.debhelper + +obj-x86_64-linux-gnu/ From 2de114b212d02588c00433b36a74da7ea5cf1398 Mon Sep 17 00:00:00 2001 From: Jan Katins Date: Fri, 2 Feb 2018 21:03:34 +0100 Subject: [PATCH 23/83] Add systemd file install to README --- README.md | 102 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 79 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 2b26772e..d09b292b 100644 --- a/README.md +++ b/README.md @@ -16,23 +16,95 @@ directory named .trash or put them in the Google Drive trash. You can always rec There are a few things that Grive does not do at the moment: - continously wait for changes in file system or in Google Drive to occur and upload. - A sync is only performed when you run Grive. + A sync is only performed when you run Grive (there are workarounds for almost + continuous sync. See below). - symbolic links support. - support for Google documents. These may be added in the future, possibly the next release. +Enjoy! + +## Usage + When Grive is run for the first time, you should use the "-a" argument to grant -permission to Grive to access to your Google Drive. A URL should be printed. -Go to the link. You will need to login to your Google account if you haven't -done so. After granting the permission to Grive, the browser will show you -an authenication code. Copy-and-paste that to the standard input of Grive. +permission to Grive to access to your Google Drive: + +```bash +cd $HOME +mkdir google-drive +cd google-drive +grive -a +``` + +A URL should be printed. Go to the link. You will need to login to your Google +account if you haven't done so. After granting the permission to Grive, the +browser will show you an authenication code. Copy-and-paste that to the +standard input of Grive. If everything works fine, Grive will create .grive and .grive_state files in your current directory. It will also start downloading files from your Google Drive to your current directory. -Enjoy! +To resync the direcory, run `grive` in the folder. + +```bash +cd $HOME/google-drive +grive +``` + +### Exclude specific files and folders from sync: .griveignore + +Rules are similar to Git's .gitignore, but may differ slightly due to the different +implementation. + +- lines that start with # are comments +- leading and trailing spaces ignored unless escaped with \ +- non-empty lines without ! in front are treated as "exclude" patterns +- non-empty lines with ! in front are treated as "include" patterns + and have a priority over all "exclude" ones +- patterns are matched against the filenames relative to the grive root +- a/**/b matches any number of subpaths between a and b, including 0 +- **/a matches `a` inside any directory +- b/** matches everything inside `b`, but not b itself +- \* matches any number of any characters except / +- ? matches any character except / +- .griveignore itself isn't ignored by default, but you can include it in itself to ignore + + +### Scheduled syncs and syncs on file change events + +There are tools which you can use to enable both scheduled syncs and syncs +when a file changes. Together these gives you an experience almost like the +Google Drive clients on other platforms (it misses the almost instantious +download of changed files in the google drive). + +Grive installs such a basic solution which uses inotify-tools together with +systemd timer and services. You can enable it for a folder in your `$HOME` +directory (in this case the `$HOME/google-drive`): + +First install the `inotify-tools` (seems to be named like that in all major distros): +test that it works by calling `inotifywait -h`. + +Prepare a Google Drive folder in your $HOME directory with `grive -a`. + +```bash +# 'google-drive' is the name of your Google Drive folder in your $HOME directory +systemctl --user enable grive-timer@google-drive.timer +systemctl --user start grive-timer@google-drive.timer +systemctl --user enable grive-changes@google-drive.service +systemctl --user start grive-changes@google-drive.service +``` + +You can enable and start these two units for multiple folders in your `$HOME` +directory if you need to sync with multiple google accounts. + +### Shared files + +Files and folders which are shared with you don't automatically show up in +your folder. They need to be added explicitly to your Google Drive: go to the +Google Drive website, right click on the file or folder and chose 'Add to My +Drive'. ## Installation @@ -87,6 +159,7 @@ Grive uses cmake to build. Basic install sequence is ### Grive2 v0.5.1-dev - support for .griveignore +- automatic sync solution based on inotify-tools and systemd - no-remote-new and upload-only modes - ignore regexp does not persist anymore (note that Grive will still track it to not accidentally delete remote files when changing ignore regexp) @@ -140,20 +213,3 @@ New features: - #86: ~~partial sync (contributed by justin at tierramedia.com)~~ that's not partial sync, that's only support for specifying local path on command line -## .griveignore - -Rules are similar to Git's .gitignore, but may differ slightly due to the different -implementation. - -- lines that start with # are comments -- leading and trailing spaces ignored unless escaped with \ -- non-empty lines without ! in front are treated as "exclude" patterns -- non-empty lines with ! in front are treated as "include" patterns - and have a priority over all "exclude" ones -- patterns are matched against the filenames relative to the grive root -- a/**/b matches any number of subpaths between a and b, including 0 -- **/a matches `a` inside any directory -- b/** matches everything inside `b`, but not b itself -- \* matches any number of any characters except / -- ? matches any character except / -- .griveignore itself isn't ignored by default, but you can include it in itself to ignore From 80bbe5f940f16d5f3e758c7eb6e2e9d6578e61f4 Mon Sep 17 00:00:00 2001 From: Topher Sterling Date: Sat, 7 Apr 2018 19:55:39 -0600 Subject: [PATCH 24/83] Adding dockerfiles for isolated build. --- .dockerignore | 1 + Dockerfile | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..191381ee --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.git \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..e0ee1c56 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM ubuntu:16.04 + +RUN apt-get update && \ + apt-get install --yes git cmake build-essential \ + libgcrypt11-dev libyajl-dev libboost-all-dev \ + libcurl4-openssl-dev libexpat1-dev libcppunit-dev \ + binutils-dev pkg-config zlib1g-dev && \ + rm -rf /var/cache/apt/archives + +VOLUME /data + +WORKDIR /data + + + +# docker build -t grive2 . +# docker run --name grive2 --rm -it -v $PWD:/data grive2:latest \ No newline at end of file From fddabe760fa739c965e3eaee29bd7673463ae199 Mon Sep 17 00:00:00 2001 From: Topher Sterling Date: Sat, 7 Apr 2018 19:56:11 -0600 Subject: [PATCH 25/83] Upping maxResults limits. --- libgrive/src/base/State.cc | 4 +++- libgrive/src/drive2/Syncer2.cc | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libgrive/src/base/State.cc b/libgrive/src/base/State.cc index 6cbf984f..68b4f484 100644 --- a/libgrive/src/base/State.cc +++ b/libgrive/src/base/State.cc @@ -162,7 +162,9 @@ void State::FromRemote( const Entry& e ) std::string k = e.IsDir() ? "folder" : "file"; // common checkings - if ( !e.IsDir() && ( fn.empty() || e.ContentSrc().empty() ) ) + if ( IsIgnore( e.Name() ) ) + Log( "file %1% is ignored by griveignore", e.Name(), log::verbose ) ; + else if ( !e.IsDir() && ( fn.empty() || e.ContentSrc().empty() ) ) Log( "%1% \"%2%\" is a google document, ignored", k, e.Name(), log::verbose ) ; else if ( fn.find('/') != fn.npos ) diff --git a/libgrive/src/drive2/Syncer2.cc b/libgrive/src/drive2/Syncer2.cc index fa5e05dd..e25632ac 100644 --- a/libgrive/src/drive2/Syncer2.cc +++ b/libgrive/src/drive2/Syncer2.cc @@ -213,12 +213,12 @@ bool Syncer2::Upload( Resource *res, bool new_rev ) std::unique_ptr Syncer2::GetFolders() { - return std::unique_ptr( new Feed2( feeds::files + "?maxResults=1000&q=trashed%3dfalse+and+mimeType%3d%27" + mime_types::folder + "%27" ) ); + return std::unique_ptr( new Feed2( feeds::files + "?maxResults=100000&q=trashed%3dfalse+and+mimeType%3d%27" + mime_types::folder + "%27" ) ); } std::unique_ptr Syncer2::GetAll() { - return std::unique_ptr( new Feed2( feeds::files + "?maxResults=1000&q=trashed%3dfalse" ) ); + return std::unique_ptr( new Feed2( feeds::files + "?maxResults=999999999&q=trashed%3dfalse" ) ); } std::string ChangesFeed( long changestamp, int maxResults = 1000 ) From 48bfe66bab59de36b493cfd7898763745806f251 Mon Sep 17 00:00:00 2001 From: Topher Sterling Date: Sat, 7 Apr 2018 20:03:42 -0600 Subject: [PATCH 26/83] Dockerfile will attempt to build the binary now. --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e0ee1c56..8120f3c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,10 +7,11 @@ RUN apt-get update && \ binutils-dev pkg-config zlib1g-dev && \ rm -rf /var/cache/apt/archives -VOLUME /data +ADD . /data WORKDIR /data +RUN mkdir build && cd build && cmake .. && make -j4 # docker build -t grive2 . From f5e1b67b4cf54b06d94474e1e408959cb5d53797 Mon Sep 17 00:00:00 2001 From: Topher Sterling Date: Sat, 7 Apr 2018 20:34:37 -0600 Subject: [PATCH 27/83] Why not just go ahead and run the executable on entry? --- .dockerignore | 5 ++++- Dockerfile | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.dockerignore b/.dockerignore index 191381ee..4b218551 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,4 @@ -.git \ No newline at end of file +.git +Dockerfile +.dockerignore +.gitignore diff --git a/Dockerfile b/Dockerfile index 8120f3c4..ad3209ec 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,11 +7,21 @@ RUN apt-get update && \ binutils-dev pkg-config zlib1g-dev && \ rm -rf /var/cache/apt/archives -ADD . /data +ADD . /grive2 + +RUN cd /grive2 && \ + mkdir build && \ + cd build && \ + cmake .. && \ + make -j4 && \ + mv /grive2/build/grive/grive /usr/local/bin/grive && \ + rm -rf /grive2 + +VOLUME /data WORKDIR /data -RUN mkdir build && cd build && cmake .. && make -j4 +ENTRYPOINT ["/usr/local/bin/grive"] # docker build -t grive2 . From 1443dd9f188557f4c11106d54548ffec7a39898e Mon Sep 17 00:00:00 2001 From: Topher Sterling Date: Sat, 7 Apr 2018 20:40:55 -0600 Subject: [PATCH 28/83] Adding dumb-init. --- Dockerfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ad3209ec..6130add1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,10 @@ RUN apt-get update && \ binutils-dev pkg-config zlib1g-dev && \ rm -rf /var/cache/apt/archives +ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /usr/local/bin/dumb-init + +RUN chmod +x /usr/local/bin/dumb-init + ADD . /grive2 RUN cd /grive2 && \ @@ -21,7 +25,7 @@ VOLUME /data WORKDIR /data -ENTRYPOINT ["/usr/local/bin/grive"] +ENTRYPOINT ["dumb-init", "/usr/local/bin/grive"] # docker build -t grive2 . From f0e38924d0f00d66eab0338874e720816093f7c3 Mon Sep 17 00:00:00 2001 From: Topher Sterling Date: Sat, 7 Apr 2018 21:41:36 -0600 Subject: [PATCH 29/83] Reduces the size of the Docker image. --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6130add1..ad5da919 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ FROM ubuntu:16.04 RUN apt-get update && \ - apt-get install --yes git cmake build-essential \ + apt-get install --yes g++ cmake build-essential \ libgcrypt11-dev libyajl-dev libboost-all-dev \ libcurl4-openssl-dev libexpat1-dev libcppunit-dev \ binutils-dev pkg-config zlib1g-dev && \ - rm -rf /var/cache/apt/archives + rm -rf /var/cache/apt/archives /var/lib/apt/lists/* ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /usr/local/bin/dumb-init From f19406e57daeca1ad63d80f9191bb6839d2c8832 Mon Sep 17 00:00:00 2001 From: Topher Sterling Date: Sat, 7 Apr 2018 21:50:20 -0600 Subject: [PATCH 30/83] Reduces the size of the Docker image. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ad5da919..a63abffb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM ubuntu:16.04 RUN apt-get update && \ - apt-get install --yes g++ cmake build-essential \ + apt-get install --yes --no-install-recommends g++ cmake build-essential \ libgcrypt11-dev libyajl-dev libboost-all-dev \ libcurl4-openssl-dev libexpat1-dev libcppunit-dev \ binutils-dev pkg-config zlib1g-dev && \ From b47dd70f35ff74362c7094a55123a1be2618e5be Mon Sep 17 00:00:00 2001 From: psfloyd Date: Sat, 12 May 2018 23:12:45 -0300 Subject: [PATCH 31/83] Exclude symlinks from sync --- systemd/grive-sync.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/systemd/grive-sync.sh b/systemd/grive-sync.sh index 36ef2e17..42d6ae8e 100755 --- a/systemd/grive-sync.sh +++ b/systemd/grive-sync.sh @@ -79,6 +79,12 @@ sync_directory() { while [[ "${TIME_AT_START}" -lt "${TIME_AT_END}" ]]; do echo "Syncing "${_directory}"..." TIME_AT_START="$(stat -c %Y "$LOCKFILE")" + # exclude symlinks from sync + cat "${_directory}"/.griveignore 2>/dev/null | sed '/#LINKS-EDIT_BEFORE_THIS$/,$d' > /tmp/.griveignore.base + cp /tmp/.griveignore.base "${_directory}"/.griveignore + rm /tmp/.griveignore.base + echo "#LINKS-EDIT_BEFORE_THIS" >> "${_directory}"/.griveignore + ( cd "${_directory}" && find . -type l | sed 's/^.\///g'; ) >> "${_directory}"/.griveignore grive -p "${_directory}" 2>&1 | grep -v -E "^Reading local directories$|^Reading remote server file list$|^Synchronizing files$|^Finished!$" TIME_AT_END="$(stat -c %Y "$LOCKFILE")" echo "Sync of "${_directory}" done." From 98d5b92e5de1a9dc17945ed0cd2e42cef426e32b Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 28 Jul 2018 23:04:01 +0300 Subject: [PATCH 32/83] Followup to fddabe760fa739c965e3eaee29bd7673463ae199 - should fix #217 --- libgrive/src/base/State.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libgrive/src/base/State.cc b/libgrive/src/base/State.cc index d186d28d..0121343a 100644 --- a/libgrive/src/base/State.cc +++ b/libgrive/src/base/State.cc @@ -162,9 +162,7 @@ void State::FromRemote( const Entry& e ) std::string k = e.IsDir() ? "folder" : "file"; // common checkings - if ( IsIgnore( e.Name() ) ) - Log( "file %1% is ignored by griveignore", e.Name(), log::verbose ) ; - else if ( !e.IsDir() && ( fn.empty() || e.ContentSrc().empty() ) ) + if ( !e.IsDir() && ( fn.empty() || e.ContentSrc().empty() ) ) Log( "%1% \"%2%\" is a google document, ignored", k, e.Name(), log::verbose ) ; else if ( fn.find('/') != fn.npos ) From 93cae255fa7a1af7f32a5271ab9e07964dbad389 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 28 Jul 2018 23:48:46 +0300 Subject: [PATCH 33/83] Fix #169 --- libgrive/src/protocol/AuthAgent.cc | 13 ++++++++++++- libgrive/src/protocol/AuthAgent.hh | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libgrive/src/protocol/AuthAgent.cc b/libgrive/src/protocol/AuthAgent.cc index 6baf1133..b15452a3 100644 --- a/libgrive/src/protocol/AuthAgent.cc +++ b/libgrive/src/protocol/AuthAgent.cc @@ -81,6 +81,7 @@ long AuthAgent::Request( { long response; Header auth; + m_interval = 0; do { auth = AppendHeader( hdr ); @@ -127,7 +128,17 @@ bool AuthAgent::CheckRetry( long response ) os::Sleep( 5 ) ; return true ; } - + // HTTP 403 is the result of API rate limiting. attempt exponential backoff and try again + else if ( response == 429 || ( response == 403 && ( + m_agent->LastError().find("\"reason\": \"userRateLimitExceeded\",") != std::string::npos || + m_agent->LastError().find("\"reason\": \"rateLimitExceeded\",") != std::string::npos ) ) ) + { + m_interval = m_interval <= 0 ? 1 : ( m_interval < 64 ? m_interval*2 : 120 ); + Log( "request failed due to rate limiting: %1% (body: %2%). retrying in %3% seconds", + response, m_agent->LastError(), m_interval, log::warning ) ; + os::Sleep( m_interval ) ; + return true ; + } // HTTP 401 Unauthorized. the auth token has been expired. refresh it else if ( response == 401 ) { diff --git a/libgrive/src/protocol/AuthAgent.hh b/libgrive/src/protocol/AuthAgent.hh index 328e8cf4..3068e7d1 100644 --- a/libgrive/src/protocol/AuthAgent.hh +++ b/libgrive/src/protocol/AuthAgent.hh @@ -71,6 +71,7 @@ private : private : OAuth2& m_auth ; http::Agent* m_agent ; + int m_interval ; } ; } // end of namespace From cbac85a8e5f37a8285516441e697b06d59a82d12 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Tue, 31 Jul 2018 01:11:09 +0300 Subject: [PATCH 34/83] Fix #218 - Impossible to ignore sub-subdirectory via griveignore Now an example .griveignore will look like this: ** !dir/subdir/subdir --- libgrive/src/base/State.cc | 97 ++++++++++++++++++++++++-------------- 1 file changed, 62 insertions(+), 35 deletions(-) diff --git a/libgrive/src/base/State.cc b/libgrive/src/base/State.cc index 0121343a..73c0d27f 100644 --- a/libgrive/src/base/State.cc +++ b/libgrive/src/base/State.cc @@ -28,6 +28,8 @@ #include "util/log/Log.hh" #include "json/JsonParser.hh" +#include + #include namespace gr { @@ -76,7 +78,7 @@ State::State( const fs::path& root, const Val& options ) : } m_ign_changed = m_orig_ign != "" && m_orig_ign != m_ign; - m_ign_re = boost::regex( m_ign.empty() ? "^\\.(grive$|grive_state$|trash)" : ( m_ign+"|^\\.(grive|grive_state|trash)" ) ); + m_ign_re = boost::regex( m_ign.empty() ? "^\\.(grive$|grive_state$|trash)" : ( m_ign+"|^\\.(grive$|grive_state$|trash)" ) ); } State::~State() @@ -93,7 +95,7 @@ void State::FromLocal( const fs::path& p ) bool State::IsIgnore( const std::string& filename ) { - return regex_search( filename.c_str(), m_ign_re ); + return regex_search( filename.c_str(), m_ign_re, boost::format_perl ); } void State::FromLocal( const fs::path& p, Resource* folder, Val& tree ) @@ -106,7 +108,7 @@ void State::FromLocal( const fs::path& p, Resource* folder, Val& tree ) for ( fs::directory_iterator i( p ) ; i != fs::directory_iterator() ; ++i ) { std::string fname = i->path().filename().string() ; - std::string path = folder->IsRoot() ? fname : ( folder->RelPath() / fname ).string(); + std::string path = ( folder->IsRoot() ? fname : ( folder->RelPath() / fname ).string() ); if ( IsIgnore( path ) ) Log( "file %1% is ignored by grive", path, log::verbose ) ; @@ -317,53 +319,78 @@ void State::Read() } } +std::vector split( const boost::regex& re, const char* str, int len ) +{ + std::vector vec; + boost::cregex_token_iterator i( str, str+len, re, -1, boost::format_perl ); + boost::cregex_token_iterator j; + while ( i != j ) + { + vec.push_back( *i++ ); + } + return vec; +} + bool State::ParseIgnoreFile( const char* buffer, int size ) { - const boost::regex re1( "/\\\\\\*\\\\\\*$" ); - const boost::regex re2( "^\\\\\\*\\\\\\*/" ); - const boost::regex re3( "([^\\\\](\\\\\\\\)*)/\\\\\\*\\\\\\*/" ); - const boost::regex re4( "([^\\\\](\\\\\\\\)*|^)\\\\\\*" ); + const boost::regex re1( "([^\\\\]|^)[\\t\\r ]+$" ); + const boost::regex re2( "^[\\t\\r ]+" ); const boost::regex re5( "([^\\\\](\\\\\\\\)*|^)\\\\\\?" ); std::string exclude_re, include_re; - int prev = 0; - for ( int i = 0; i <= size; i++ ) + std::vector lines = split( boost::regex( "[\\n\\r]+" ), buffer, size ); + for ( int i = 0; i < (int)lines.size(); i++ ) { - if ( buffer[i] == '\n' || ( i == size && i > prev ) ) + std::string str = regex_replace( regex_replace( lines[i], re1, "$1" ), re2, "" ); + if ( str[0] == '#' || !str.size() ) { - while ( prev < i && ( buffer[prev] == ' ' || buffer[prev] == '\t' || buffer[prev] == '\r' ) ) - prev++; - if ( buffer[prev] != '#' ) + continue; + } + bool inc = str[0] == '!'; + if ( inc ) + { + str = str.substr( 1 ); + } + std::vector parts = split( boost::regex( "/+" ), str.c_str(), str.size() ); + for ( int j = 0; j < (int)parts.size(); j++ ) + { + if ( parts[j] == "**" ) { - int j; - for ( j = i-1; j > prev; j-- ) - if ( buffer[j-1] == '\\' || ( buffer[j] != ' ' && buffer[j] != '\t' && buffer[j] != '\r' ) ) - break; - std::string str( buffer+prev, j+1-prev ); - bool inc = str[0] == '!'; - if ( inc ) - str = str.substr( 1 ); - str = regex_escape( str ); - str = regex_replace( str, re1, "/.*", boost::format_perl ); - str = regex_replace( str, re2, ".*/", boost::format_perl ); - str = regex_replace( str, re3, "$1/(.*/)*", boost::format_perl ); - str = regex_replace( str, re4, "$1[^/]*", boost::format_perl ); + parts[j] = ".*"; + } + else if ( parts[j] == "*" ) + { + parts[j] = "[^/]*"; + } + else + { + parts[j] = regex_escape( parts[j] ); std::string str1; while (1) { - str1 = regex_replace( str, re5, "$1[^/]", boost::format_perl ); - if ( str1.size() == str.size() ) + str1 = regex_replace( parts[j], re5, "$1[^/]", boost::format_perl ); + if ( str1.size() == parts[j].size() ) break; - str = str1; + parts[j] = str1; } - if ( !inc ) - exclude_re = exclude_re + ( exclude_re.size() > 0 ? "|" : "" ) + str; - else - include_re = include_re + ( include_re.size() > 0 ? "|" : "" ) + str; } - prev = i+1; + } + if ( !inc ) + { + str = boost::algorithm::join( parts, "/" ) + "(/|$)"; + exclude_re = exclude_re + ( exclude_re.size() > 0 ? "|" : "" ) + str; + } + else + { + str = ""; + std::string cur; + for ( int j = 0; j < (int)parts.size(); j++ ) + { + cur = cur.size() > 0 ? cur + "/" + parts[j] : "^" + parts[j]; + str = ( str.size() > 0 ? str + "|" + cur : cur ) + ( j < (int)parts.size()-1 ? "$" : "(/|$)" ); + } + include_re = include_re + ( include_re.size() > 0 ? "|" : "" ) + str; } } - if ( exclude_re.size() > 0 ) { m_ign = "^" + ( include_re.size() > 0 ? "(?!" + include_re + ")" : std::string() ) + "(" + exclude_re + ")$"; From d4a0445873924cee567436c8899a80eb0abcef86 Mon Sep 17 00:00:00 2001 From: a martin Date: Tue, 7 Aug 2018 15:04:26 -0400 Subject: [PATCH 35/83] Added the install instruction for Fedora Tested on Fedora 28 --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index d09b292b..36dc5df8 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,11 @@ these packages: libboost-all-dev libcurl4-openssl-dev libexpat1-dev libcppunit-dev binutils-dev \ debhelper zlib1g-dev dpkg-dev pkg-config +Fedora: + + sudo dnf install git cmake libgcrypt-devel g++ libstdc++ yajl-devel boost libcurl-devel expat-devel binutils zlib + + FreeBSD: pkg install git cmake boost-libs yajl libgcrypt pkgconf cppunit libbfd From cf51167b55246b7f90ad4970d9686637e8bb0beb Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 19 Aug 2018 23:58:06 +0300 Subject: [PATCH 36/83] Return lost * matching back - fixes #223 --- libgrive/src/base/State.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libgrive/src/base/State.cc b/libgrive/src/base/State.cc index 73c0d27f..9f414bbf 100644 --- a/libgrive/src/base/State.cc +++ b/libgrive/src/base/State.cc @@ -335,6 +335,7 @@ bool State::ParseIgnoreFile( const char* buffer, int size ) { const boost::regex re1( "([^\\\\]|^)[\\t\\r ]+$" ); const boost::regex re2( "^[\\t\\r ]+" ); + const boost::regex re4( "([^\\\\](\\\\\\\\)*|^)\\\\\\*" ); const boost::regex re5( "([^\\\\](\\\\\\\\)*|^)\\\\\\?" ); std::string exclude_re, include_re; std::vector lines = split( boost::regex( "[\\n\\r]+" ), buffer, size ); @@ -368,6 +369,7 @@ bool State::ParseIgnoreFile( const char* buffer, int size ) while (1) { str1 = regex_replace( parts[j], re5, "$1[^/]", boost::format_perl ); + str1 = regex_replace( str1, re4, "$1[^/]*", boost::format_perl ); if ( str1.size() == parts[j].size() ) break; parts[j] = str1; From 60ecd5b0ff71840e3054f9966cf2ee012119fd3f Mon Sep 17 00:00:00 2001 From: Alex Martin Date: Mon, 8 Oct 2018 13:36:37 -0400 Subject: [PATCH 37/83] Changed the g++ package to gcc-c++ Fixed the Fedora install directions. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 36dc5df8..f1546f8e 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ these packages: Fedora: - sudo dnf install git cmake libgcrypt-devel g++ libstdc++ yajl-devel boost libcurl-devel expat-devel binutils zlib + sudo dnf install git cmake libgcrypt-devel gcc-c++ libstdc++ yajl-devel boost libcurl-devel expat-devel binutils zlib FreeBSD: From e3e18fe16aec7b5ae849275234fbd824e4c83a95 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Mon, 3 Dec 2018 21:21:49 +0100 Subject: [PATCH 38/83] Escape folder when calling sync from change listener The old version would pass in an unescaped directory, which then got unescaped by the sync call. In some cases it worked but resulted in foldername wold not matched reality (example: google-drive -> google/drive) and error out when checking if that folder exists. --- systemd/grive-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemd/grive-sync.sh b/systemd/grive-sync.sh index 42d6ae8e..bb837ba3 100755 --- a/systemd/grive-sync.sh +++ b/systemd/grive-sync.sh @@ -107,7 +107,7 @@ listen_directory() { while true #run indefinitely do # Use a different call to not need to change exit into return - inotifywait -q -r -e modify,attrib,close_write,move,create,delete --exclude ".grive_state|.grive" "${_directory}" > /dev/null 2>&1 && ${SCRIPT} sync "${_directory}" + inotifywait -q -r -e modify,attrib,close_write,move,create,delete --exclude ".grive_state|.grive" "${_directory}" > /dev/null 2>&1 && ${SCRIPT} sync $(systemd-escape "${_directory}") #echo ${SCRIPT} "${_directory}" done From f9cad3b635d91059e2b6b7fdf19558411acb6bee Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Mon, 3 Dec 2018 21:34:10 +0100 Subject: [PATCH 39/83] Update readme how to enable and start systemd units It missed that escaping was essential if you didn't use a all [a-z] foldername... --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d09b292b..0e1da4cf 100644 --- a/README.md +++ b/README.md @@ -90,10 +90,10 @@ Prepare a Google Drive folder in your $HOME directory with `grive -a`. ```bash # 'google-drive' is the name of your Google Drive folder in your $HOME directory -systemctl --user enable grive-timer@google-drive.timer -systemctl --user start grive-timer@google-drive.timer -systemctl --user enable grive-changes@google-drive.service -systemctl --user start grive-changes@google-drive.service +systemctl --user enable grive-timer@$(systemd-escape google-drive).timer +systemctl --user start grive-timer@$(systemd-escape google-drive).timer +systemctl --user enable grive-changes@$(systemd-escape google-drive).service +systemctl --user start grive-changes@$(systemd-escape google-drive).service ``` You can enable and start these two units for multiple folders in your `$HOME` From 8e3c3d25cb51dc2ceb2044dec545dc4028cfe39a Mon Sep 17 00:00:00 2001 From: Andrew Udvare Date: Fri, 8 Feb 2019 18:10:21 -0500 Subject: [PATCH 40/83] Define off64_t=off_t for macOS Detect the systemd binary and install the systemd units conditionally. --- CMakeLists.txt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 951d8749..2373eb5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,8 +8,19 @@ set( GRIVE_VERSION "0.5.1-dev" ) # common compile options add_definitions( -DVERSION="${GRIVE_VERSION}" ) add_definitions( -D_FILE_OFFSET_BITS=64 -std=c++0x ) +if ( APPLE ) + add_definitions( -Doff64_t=off_t ) +endif ( APPLE ) + +find_program( + HAVE_SYSTEMD systemd + PATHS /lib/systemd /usr/lib/systemd + NO_DEFAULT_PATH +) +if ( HAVE_SYSTEMD ) + add_subdirectory( systemd ) +endif( NOT HAVE_SYSTEMD ) -add_subdirectory( systemd ) add_subdirectory( libgrive ) add_subdirectory( grive ) - \ No newline at end of file + From e972a77790d7e42bb71822a06836d38ec9b5537f Mon Sep 17 00:00:00 2001 From: Tatsh Date: Sat, 9 Feb 2019 10:56:23 -0500 Subject: [PATCH 41/83] Fix line --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2373eb5e..737f6964 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ find_program( ) if ( HAVE_SYSTEMD ) add_subdirectory( systemd ) -endif( NOT HAVE_SYSTEMD ) +endif( HAVE_SYSTEMD ) add_subdirectory( libgrive ) add_subdirectory( grive ) From 7ef50e9523b230876905ed437ed0b1eeefd14dc9 Mon Sep 17 00:00:00 2001 From: Andrew Udvare Date: Sat, 9 Feb 2019 17:01:00 -0500 Subject: [PATCH 42/83] libgrive: Fix destructors of Feed and Feed2 --- libgrive/src/base/Feed.cc | 4 ++++ libgrive/src/base/Feed.hh | 1 + libgrive/src/drive2/Feed2.cc | 4 ++++ libgrive/src/drive2/Feed2.hh | 1 + 4 files changed, 10 insertions(+) diff --git a/libgrive/src/base/Feed.cc b/libgrive/src/base/Feed.cc index 0ea834d3..0a4f51b1 100644 --- a/libgrive/src/base/Feed.cc +++ b/libgrive/src/base/Feed.cc @@ -30,6 +30,10 @@ Feed::Feed( const std::string &url ): { } +Feed::~Feed() +{ +} + Feed::iterator Feed::begin() const { return m_entries.begin() ; diff --git a/libgrive/src/base/Feed.hh b/libgrive/src/base/Feed.hh index d43c68ce..fc73e75a 100644 --- a/libgrive/src/base/Feed.hh +++ b/libgrive/src/base/Feed.hh @@ -41,6 +41,7 @@ public : public : Feed( const std::string& url ); virtual bool GetNext( http::Agent *http ) = 0 ; + virtual ~Feed() = 0 ; iterator begin() const ; iterator end() const ; diff --git a/libgrive/src/drive2/Feed2.cc b/libgrive/src/drive2/Feed2.cc index 8f3d2344..037df373 100644 --- a/libgrive/src/drive2/Feed2.cc +++ b/libgrive/src/drive2/Feed2.cc @@ -36,6 +36,10 @@ Feed2::Feed2( const std::string& url ): { } +Feed2::~Feed2() +{ +} + bool Feed2::GetNext( http::Agent *http ) { if ( m_next.empty() ) diff --git a/libgrive/src/drive2/Feed2.hh b/libgrive/src/drive2/Feed2.hh index 4de411e9..453c60d1 100644 --- a/libgrive/src/drive2/Feed2.hh +++ b/libgrive/src/drive2/Feed2.hh @@ -31,6 +31,7 @@ class Feed2: public Feed { public : Feed2( const std::string& url ) ; + ~Feed2() ; bool GetNext( http::Agent *http ) ; } ; From 6354689a939518d2168b04c398500d119ec35ef8 Mon Sep 17 00:00:00 2001 From: Andrew Udvare Date: Sat, 9 Feb 2019 17:06:23 -0500 Subject: [PATCH 43/83] libgrive: fix formatting --- libgrive/src/base/Feed.hh | 2 +- libgrive/src/drive2/Feed2.hh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libgrive/src/base/Feed.hh b/libgrive/src/base/Feed.hh index fc73e75a..c12f5070 100644 --- a/libgrive/src/base/Feed.hh +++ b/libgrive/src/base/Feed.hh @@ -41,7 +41,7 @@ public : public : Feed( const std::string& url ); virtual bool GetNext( http::Agent *http ) = 0 ; - virtual ~Feed() = 0 ; + virtual ~Feed() = 0 ; iterator begin() const ; iterator end() const ; diff --git a/libgrive/src/drive2/Feed2.hh b/libgrive/src/drive2/Feed2.hh index 453c60d1..c5643f6f 100644 --- a/libgrive/src/drive2/Feed2.hh +++ b/libgrive/src/drive2/Feed2.hh @@ -31,7 +31,7 @@ class Feed2: public Feed { public : Feed2( const std::string& url ) ; - ~Feed2() ; + ~Feed2() ; bool GetNext( http::Agent *http ) ; } ; From d4742fd470fb160bd6bff4f9364a5b826d4a5367 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Wed, 5 Dec 2018 00:03:44 +0100 Subject: [PATCH 44/83] Remove unneded link-time dependency on libz and libexpat --- libgrive/CMakeLists.txt | 7 ------- libgrive/src/xml/TreeBuilder.cc | 1 - 2 files changed, 8 deletions(-) diff --git a/libgrive/CMakeLists.txt b/libgrive/CMakeLists.txt index d9dbebb6..c7ad3cb5 100644 --- a/libgrive/CMakeLists.txt +++ b/libgrive/CMakeLists.txt @@ -4,12 +4,10 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") find_package(LibGcrypt REQUIRED) find_package(CURL REQUIRED) -find_package(EXPAT REQUIRED) find_package(Boost 1.40.0 COMPONENTS program_options filesystem unit_test_framework regex system REQUIRED) find_package(BFD) find_package(CppUnit) find_package(Iberty) -find_package(ZLIB) find_package(PkgConfig) pkg_check_modules(YAJL REQUIRED yajl) @@ -37,10 +35,6 @@ else ( IBERTY_FOUND ) set( IBERTY_LIBRARY "" ) endif ( IBERTY_FOUND ) -if ( ZLIB_FOUND ) - set( OPT_LIBS ${OPT_LIBS} ${ZLIB_LIBRARIES} ) -endif ( ZLIB_FOUND ) - include_directories( ${libgrive_SOURCE_DIR}/src ${libgrive_SOURCE_DIR}/test @@ -88,7 +82,6 @@ target_link_libraries( grive ${Boost_REGEX_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${IBERTY_LIBRARY} - ${EXPAT_LIBRARY} ${OPT_LIBS} ) diff --git a/libgrive/src/xml/TreeBuilder.cc b/libgrive/src/xml/TreeBuilder.cc index 9d57501b..14142557 100644 --- a/libgrive/src/xml/TreeBuilder.cc +++ b/libgrive/src/xml/TreeBuilder.cc @@ -23,7 +23,6 @@ #include "Node.hh" #include "util/log/Log.hh" -#include #include #include From fe17d715fc775cd5228d886ddc7289b9f922acf4 Mon Sep 17 00:00:00 2001 From: Gianluca Recchia Date: Wed, 30 Oct 2019 17:37:11 +0100 Subject: [PATCH 45/83] Add 'project' directive to the build script --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 951d8749..a78aa840 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,5 @@ cmake_minimum_required(VERSION 2.8) +project(grive2) include(GNUInstallDirs) @@ -12,4 +13,3 @@ add_definitions( -D_FILE_OFFSET_BITS=64 -std=c++0x ) add_subdirectory( systemd ) add_subdirectory( libgrive ) add_subdirectory( grive ) - \ No newline at end of file From 13ac9bd1a96fc0e1b84c7f4a49f53874c210fc14 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Mon, 11 Nov 2019 21:10:40 +0300 Subject: [PATCH 46/83] Add ACHTUNG note to the README --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 4d37a7de..eef78e6f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,19 @@ +# ACHTUNG + +Most of Google Drive APIs are currently locked. R.I.P grive2 and other opensource +Google Drive clients :) + +Details: + +Here https://developers.google.com/drive/api/v3/about-auth?hl=ru most APIs are marked as restricted + +And here https://support.google.com/cloud/answer/9110914 they say that + +**The following application types are examples of apps that are no longer allowed per the Permitted Application Types policy: +Apps that store or backup data other than email messages in Gmail.** + +So, go tell Google they're morons and quit using google drive NOW :) + # Grive2 0.5.1-dev 28 Sep 2016, Vitaliy Filippov From 548ea362f319cd1f7fcbad0344fde8449fa14255 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Wed, 13 Nov 2019 01:04:29 +0300 Subject: [PATCH 47/83] Update client_id and client_secret -> maybe Google will verify it? --- CMakeLists.txt | 2 +- README.md | 47 +++++++++++++-------------------- grive/src/main.cc | 4 +-- libgrive/src/protocol/OAuth2.cc | 7 +---- 4 files changed, 22 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 951d8749..1b3f9a12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8) include(GNUInstallDirs) # Grive version. remember to update it for every new release! -set( GRIVE_VERSION "0.5.1-dev" ) +set( GRIVE_VERSION "0.5.1" ) # common compile options add_definitions( -DVERSION="${GRIVE_VERSION}" ) diff --git a/README.md b/README.md index eef78e6f..ff3cb4f7 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,14 @@ -# ACHTUNG +# Grive2 0.5.2-dev -Most of Google Drive APIs are currently locked. R.I.P grive2 and other opensource -Google Drive clients :) - -Details: - -Here https://developers.google.com/drive/api/v3/about-auth?hl=ru most APIs are marked as restricted - -And here https://support.google.com/cloud/answer/9110914 they say that - -**The following application types are examples of apps that are no longer allowed per the Permitted Application Types policy: -Apps that store or backup data other than email messages in Gmail.** - -So, go tell Google they're morons and quit using google drive NOW :) - -# Grive2 0.5.1-dev - -28 Sep 2016, Vitaliy Filippov +13 Nov 2019, Vitaliy Filippov http://yourcmc.ru/wiki/Grive2 This is the fork of original "Grive" (https://github.com/Grive/grive) Google Drive client with the support for the new Drive REST API and partial sync. -Grive can be considered still beta or pre-beta quality. It simply downloads all the files in your -Google Drive into the current directory. After you make some changes to the local files, run +Grive simply downloads all the files in your Google Drive into the current directory. +After you make some changes to the local files, run grive again and it will upload your changes back to your Google Drive. New files created locally or in Google Drive will be uploaded or downloaded respectively. Deleted files will also be "removed". Currently Grive will NOT destroy any of your files: it will only move the files to a @@ -32,12 +16,12 @@ directory named .trash or put them in the Google Drive trash. You can always rec There are a few things that Grive does not do at the moment: - continously wait for changes in file system or in Google Drive to occur and upload. - A sync is only performed when you run Grive (there are workarounds for almost + A sync is only performed when you run Grive (there are workarounds for almost continuous sync. See below). - symbolic links support. - support for Google documents. -These may be added in the future, possibly the next release. +These may be added in the future. Enjoy! @@ -177,17 +161,22 @@ Grive uses cmake to build. Basic install sequence is ## Version History -### Grive2 v0.5.1-dev +### Grive2 v0.5.2-dev + +### Grive2 v0.5.1 -- support for .griveignore -- automatic sync solution based on inotify-tools and systemd +- Support for .griveignore +- Automatic sync solution based on inotify-tools and systemd - no-remote-new and upload-only modes -- ignore regexp does not persist anymore (note that Grive will still track it to not +- Ignore regexp does not persist anymore (note that Grive will still track it to not accidentally delete remote files when changing ignore regexp) -- added options to limit upload and download speed -- faster upload of new and changed files. now Grive uploads files without first calculating +- Added options to limit upload and download speed +- Faster upload of new and changed files. Now Grive uploads files without first calculating md5 checksum when file is created locally or when its size changes. -- added -P/--progress-bar option to print ASCII progress bar for each processed file (pull request by @svartkanin) +- Added -P/--progress-bar option to print ASCII progress bar for each processed file (pull request by @svartkanin) +- Added command-line options to specify your own client_id and client_secret +- Now grive2 skips links, sockets, fifos and other unusual files +- Various small build fixes ### Grive2 v0.5 diff --git a/grive/src/main.cc b/grive/src/main.cc index 7f0bd33c..31a2b078 100644 --- a/grive/src/main.cc +++ b/grive/src/main.cc @@ -46,8 +46,8 @@ #include #include -const std::string default_id = "22314510474.apps.googleusercontent.com" ; -const std::string default_secret = "bl4ufi89h-9MkFlypcI7R785" ; +const std::string default_id = "615557989097-i93d4d1ojpen0m0dso18ldr6orjkidgf.apps.googleusercontent.com" ; +const std::string default_secret = "xiM8Apu_WuRRdheNelJcNtOD" ; using namespace gr ; namespace po = boost::program_options; diff --git a/libgrive/src/protocol/OAuth2.cc b/libgrive/src/protocol/OAuth2.cc index 73ae0886..db1858aa 100644 --- a/libgrive/src/protocol/OAuth2.cc +++ b/libgrive/src/protocol/OAuth2.cc @@ -84,12 +84,7 @@ void OAuth2::Auth( const std::string& auth_code ) std::string OAuth2::MakeAuthURL() { return "https://accounts.google.com/o/oauth2/auth" - "?scope=" + - m_agent->Escape( "https://www.googleapis.com/auth/userinfo.email" ) + "+" + - m_agent->Escape( "https://www.googleapis.com/auth/userinfo.profile" ) + "+" + - m_agent->Escape( "https://docs.google.com/feeds/" ) + "+" + - m_agent->Escape( "https://docs.googleusercontent.com/" ) + "+" + - m_agent->Escape( "https://spreadsheets.google.com/feeds/" ) + + "?scope=" + m_agent->Escape( "https://www.googleapis.com/auth/drive" ) + "&redirect_uri=urn:ietf:wg:oauth:2.0:oob" "&response_type=code" "&client_id=" + m_client_id ; From 39299096cf140534ee522bb04f3d6f1446ed1b95 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Wed, 13 Nov 2019 01:06:03 +0300 Subject: [PATCH 48/83] Move to 0.5.2-dev --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b3f9a12..d2937a93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.8) include(GNUInstallDirs) # Grive version. remember to update it for every new release! -set( GRIVE_VERSION "0.5.1" ) +set( GRIVE_VERSION "0.5.2-dev" ) # common compile options add_definitions( -DVERSION="${GRIVE_VERSION}" ) From ad7844ba29eebb7010bb4b67823daa6a2eadfb30 Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 22 Nov 2019 09:35:43 -0300 Subject: [PATCH 49/83] modified: README.md modified: debian/rules --- README.md | 6 +++++- debian/rules | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ff3cb4f7..18d60a97 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,10 @@ your folder. They need to be added explicitly to your Google Drive: go to the Google Drive website, right click on the file or folder and chose 'Add to My Drive'. +## Custom client id and secret + +You can specify them with --id and --secret arguments or edit them at grive/src/main.cpp and rebuild. + ## Installation For the detailed instructions, see http://yourcmc.ru/wiki/Grive2#Installation @@ -147,7 +151,7 @@ FreeBSD: On a Debian/Ubuntu/Linux Mint you can use `dpkg-buildpackage` utility from `dpkg-dev` package to build grive. Just clone the repository, `cd` into it and run - dpkg-buildpackage -j4 + dpkg-buildpackage -j4 --no-sign ### Manual build diff --git a/debian/rules b/debian/rules index 81484573..61596921 100755 --- a/debian/rules +++ b/debian/rules @@ -1,4 +1,4 @@ #!/usr/bin/make -f %: - dh $@ --buildsystem=cmake --parallel + dh $@ --buildsystem=cmake --parallel --builddirectory=build From 79312b9c53bc64bd2bee1b929e4185ee061c75c7 Mon Sep 17 00:00:00 2001 From: AmonRaNet Date: Fri, 13 Dec 2019 11:16:32 +0100 Subject: [PATCH 50/83] Extends support application id and secret support - persistent id's in config - cmake supports id's during config - priority: default(cmake), config, cli --- CMakeLists.txt | 4 ++-- README.md | 8 ++++++++ grive/CMakeLists.txt | 11 +++++++++++ grive/src/main.cc | 37 ++++++++++++++++++++++--------------- libgrive/src/util/Config.cc | 4 ++++ 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d2937a93..71dcb771 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,8 @@ cmake_minimum_required(VERSION 2.8) include(GNUInstallDirs) # Grive version. remember to update it for every new release! -set( GRIVE_VERSION "0.5.2-dev" ) +set( GRIVE_VERSION "0.5.2-dev" CACHE STRING "Grive version" ) +message(WARNING "Version to build: ${GRIVE_VERSION}") # common compile options add_definitions( -DVERSION="${GRIVE_VERSION}" ) @@ -12,4 +13,3 @@ add_definitions( -D_FILE_OFFSET_BITS=64 -std=c++0x ) add_subdirectory( systemd ) add_subdirectory( libgrive ) add_subdirectory( grive ) - \ No newline at end of file diff --git a/README.md b/README.md index ff3cb4f7..d9a0da2a 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,14 @@ Grive uses cmake to build. Basic install sequence is make -j4 sudo make install +Alternativly you can define your own client_id and client_secret during build + + mkdir build + cd build + cmake .. "-DAPP_ID:STRING=" "-DAPP_SECRET:STRING=" + make -j4 + sudo make install + ## Version History ### Grive2 v0.5.2-dev diff --git a/grive/CMakeLists.txt b/grive/CMakeLists.txt index 0908380b..ac5b781d 100644 --- a/grive/CMakeLists.txt +++ b/grive/CMakeLists.txt @@ -20,6 +20,17 @@ target_link_libraries( grive_executable grive ) +set(DEFAULT_APP_ID "615557989097-i93d4d1ojpen0m0dso18ldr6orjkidgf.apps.googleusercontent.com") +set(DEFAULT_APP_SECRET "xiM8Apu_WuRRdheNelJcNtOD") +set(APP_ID ${DEFAULT_APP_ID} CACHE STRING "Application Id") +set(APP_SECRET ${DEFAULT_APP_SECRET} CACHE STRING "Application Secret") + +target_compile_definitions ( grive_executable + PRIVATE + -DAPP_ID="${APP_ID}" + -DAPP_SECRET="${APP_SECRET}" +) + set_target_properties( grive_executable PROPERTIES OUTPUT_NAME grive ) diff --git a/grive/src/main.cc b/grive/src/main.cc index 31a2b078..54d5560b 100644 --- a/grive/src/main.cc +++ b/grive/src/main.cc @@ -46,8 +46,8 @@ #include #include -const std::string default_id = "615557989097-i93d4d1ojpen0m0dso18ldr6orjkidgf.apps.googleusercontent.com" ; -const std::string default_secret = "xiM8Apu_WuRRdheNelJcNtOD" ; +const std::string default_id = APP_ID ; +const std::string default_secret = APP_SECRET ; using namespace gr ; namespace po = boost::program_options; @@ -113,6 +113,7 @@ int Main( int argc, char **argv ) ( "auth,a", "Request authorization token" ) ( "id,i", po::value(), "Authentication ID") ( "secret,e", po::value(), "Authentication secret") + ( "print-url", "Only print url for request") ( "path,p", po::value(), "Path to working copy root") ( "dir,s", po::value(), "Single subdirectory to sync") ( "verbose,V", "Verbose mode. Enable more messages than normal.") @@ -174,23 +175,23 @@ int Main( int argc, char **argv ) http->SetProgressReporter( pb.get() ); } - std::string id = default_id; - std::string secret = default_secret; - - if( vm.count( "id" ) ) - { - id = vm["id"].as(); - } - - if( vm.count( "secret" ) ) - { - secret = vm["secret"].as(); - } - if ( vm.count( "auth" ) ) { + std::string id = vm.count( "id" ) > 0 + ? vm["id"].as() + : default_id ; + std::string secret = vm.count( "secret" ) > 0 + ? vm["secret"].as() + : default_secret ; + OAuth2 token( http.get(), id, secret ) ; + if ( vm.count("print-url") ) + { + std::cout << token.MakeAuthURL() << std::endl ; + return 0 ; + } + std::cout << "-----------------------\n" << "Please go to this URL and get an authentication code:\n\n" @@ -206,14 +207,20 @@ int Main( int argc, char **argv ) token.Auth( code ) ; // save to config + config.Set( "id", Val( id ) ) ; + config.Set( "secret", Val( secret ) ) ; config.Set( "refresh_token", Val( token.RefreshToken() ) ) ; config.Save() ; } std::string refresh_token ; + std::string id ; + std::string secret ; try { refresh_token = config.Get("refresh_token").Str() ; + id = config.Get("id").Str() ; + secret = config.Get("secret").Str() ; } catch ( Exception& e ) { diff --git a/libgrive/src/util/Config.cc b/libgrive/src/util/Config.cc index ba0c91e3..c08972f6 100644 --- a/libgrive/src/util/Config.cc +++ b/libgrive/src/util/Config.cc @@ -38,6 +38,10 @@ const std::string default_root_folder = "."; Config::Config( const po::variables_map& vm ) { + if ( vm.count( "id" ) > 0 ) + m_cmd.Add( "id", Val( vm["id"].as() ) ) ; + if ( vm.count( "secret" ) > 0 ) + m_cmd.Add( "secret", Val( vm["secret"].as() ) ) ; m_cmd.Add( "new-rev", Val(vm.count("new-rev") > 0) ) ; m_cmd.Add( "force", Val(vm.count("force") > 0 ) ) ; m_cmd.Add( "path", Val(vm.count("path") > 0 From de6404b246e8658f1559079467e451a2419a10c5 Mon Sep 17 00:00:00 2001 From: Frank Bicknell Date: Mon, 16 Dec 2019 13:27:43 -0500 Subject: [PATCH 51/83] Fix Fedora (and RHEL) suggested dependencies We need boost-devel to compile. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d9a0da2a..b54b28d1 100644 --- a/README.md +++ b/README.md @@ -135,7 +135,7 @@ these packages: Fedora: - sudo dnf install git cmake libgcrypt-devel gcc-c++ libstdc++ yajl-devel boost libcurl-devel expat-devel binutils zlib + sudo dnf install git cmake libgcrypt-devel gcc-c++ libstdc++ yajl-devel boost-devel libcurl-devel expat-devel binutils zlib FreeBSD: From 94182975db1941b409af466486749fc41f0108f2 Mon Sep 17 00:00:00 2001 From: AmonRaNet Date: Tue, 31 Dec 2019 20:13:26 +0100 Subject: [PATCH 52/83] Add instruction for replacing the OAuth2 client --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index d9a0da2a..4581df0a 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,31 @@ your folder. They need to be added explicitly to your Google Drive: go to the Google Drive website, right click on the file or folder and chose 'Add to My Drive'. +### Different OAuth2 client to workaround over quota issues + +The default OAuth2 client supplied with grive is sometimes over quota and grive +will then fail to sync. You can supply your own OAuth2 client credentials by +following these steps: + +1. Go to https://console.developers.google.com/apis/api/drive.googleapis.com +2. Chose a project (you might need to create one first) +3. Go to https://console.developers.google.com/apis/library/drive.googleapis.com and + "Enable" the Google Drive APIs +4. Create new Credentials on the folloing screen(s) +5. In the "Find out what credentials you need" dialog, choose: + - Which API are you using: "Google Drive API" + - Where will you be calling the API from: "Other UI (...CLI...)" + - What data will you be accessing: "User Data" +6. In the next steps create a client id (name doesn't matter) and + setup the consent screen (defaults are ok, no need for any URLs) +7. The needed "Client ID" and "Client Secret" are either in the shown download + or can later found by clicking on the created credential on + https://console.developers.google.com/apis/credentials/ +8. When you applying grive in an existing Google Drive folder, you must first delete + the old `.grive` configuration file. +9. Call `grive -a --id --secret ` and follow the steps + to authenticate the OAuth2 client to allow it to access your drive folder. + ## Installation For the detailed instructions, see http://yourcmc.ru/wiki/Grive2#Installation From a3cce716439536f85235c2d3eb2151f671a80c29 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Mon, 6 Jan 2020 20:32:44 +0300 Subject: [PATCH 53/83] Small corrections --- README.md | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4581df0a..43b78cd3 100644 --- a/README.md +++ b/README.md @@ -106,17 +106,23 @@ your folder. They need to be added explicitly to your Google Drive: go to the Google Drive website, right click on the file or folder and chose 'Add to My Drive'. -### Different OAuth2 client to workaround over quota issues +### Different OAuth2 client to workaround over quota and google approval issues -The default OAuth2 client supplied with grive is sometimes over quota and grive -will then fail to sync. You can supply your own OAuth2 client credentials by -following these steps: +Google recently started to restrict access for unapproved applications: +https://developers.google.com/drive/api/v3/about-auth?hl=ru + +Grive2 is currently awaiting approval but it seems it will take forever. +Also even if they approve it the default Client ID supplied with grive may +exceed quota and grive will then fail to sync. + +You can supply your own OAuth2 client credentials to work around these problems +by following these steps: 1. Go to https://console.developers.google.com/apis/api/drive.googleapis.com -2. Chose a project (you might need to create one first) +2. Choose a project (you might need to create one first) 3. Go to https://console.developers.google.com/apis/library/drive.googleapis.com and "Enable" the Google Drive APIs -4. Create new Credentials on the folloing screen(s) +4. Go to https://console.cloud.google.com/apis/credentials and click "Create credentials > Help me choose" 5. In the "Find out what credentials you need" dialog, choose: - Which API are you using: "Google Drive API" - Where will you be calling the API from: "Other UI (...CLI...)" @@ -126,7 +132,7 @@ following these steps: 7. The needed "Client ID" and "Client Secret" are either in the shown download or can later found by clicking on the created credential on https://console.developers.google.com/apis/credentials/ -8. When you applying grive in an existing Google Drive folder, you must first delete +8. When you change client ID/secret in an existing Grive folder you must first delete the old `.grive` configuration file. 9. Call `grive -a --id --secret ` and follow the steps to authenticate the OAuth2 client to allow it to access your drive folder. From b4d6ac055f8f16ac735a70036243bc4ea2334039 Mon Sep 17 00:00:00 2001 From: Giuseppe Corbelli Date: Tue, 14 Jan 2020 11:50:20 +0100 Subject: [PATCH 54/83] [SymbolInfo.cc] Support compilation with binutils >= 2.33.1 on Debian. bfd_get_section_vma macro was removed. bfd_section_size changed signature. See inline comment for details. --- libgrive/src/bfd/SymbolInfo.cc | 35 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/libgrive/src/bfd/SymbolInfo.cc b/libgrive/src/bfd/SymbolInfo.cc index 5876cc00..cdb5d7c7 100644 --- a/libgrive/src/bfd/SymbolInfo.cc +++ b/libgrive/src/bfd/SymbolInfo.cc @@ -49,9 +49,9 @@ SymbolInfo::SymbolInfo( ) m_impl->m_bfd = 0 ; m_impl->m_symbols = 0 ; m_impl->m_symbol_count = 0 ; - + bfd_init( ) ; - + // opening itself bfd *b = bfd_openr( "/proc/self/exe", 0 ) ; if ( b == NULL ) @@ -60,13 +60,13 @@ SymbolInfo::SymbolInfo( ) << bfd_errmsg( bfd_get_error() ) << std::endl ; return ; } - + if ( bfd_check_format( b, bfd_archive ) ) { bfd_close( b ) ; return ; } - + char **matching ; if ( !bfd_check_format_matches( b, bfd_object, &matching ) ) { @@ -78,7 +78,7 @@ SymbolInfo::SymbolInfo( ) std::cerr << bfd_get_filename( b ) << ": Matching formats: " ; for ( char **p = matching ; *p != 0 ; p++ ) std::cerr << " " << *p ; - + std::cerr << std::endl ; std::free( matching ) ; } @@ -107,7 +107,7 @@ struct SymbolInfo::BacktraceInfo const char *m_func_name ; unsigned int m_lineno ; unsigned int m_is_found ; - + static void Callback( bfd *abfd, asection *section, void* addr ) ; } ; @@ -117,17 +117,24 @@ void SymbolInfo::BacktraceInfo::Callback( bfd *abfd, asection *section, BacktraceInfo *info = (BacktraceInfo *)data ; if ((section->flags & SEC_ALLOC) == 0) return ; - - bfd_vma vma = bfd_get_section_vma(abfd, section); - + + // bfd_get_section_vma works up to 7b1cfbcf1a27951fb1b3a212995075dd6fdf985b, + // removed in 7c13bc8c91abf291f0206b6608b31955c5ea70d8 (binutils 2.33.1 or so) + // so it's substituted by its implementation to avoid checking for binutils + // version (which at least on Debian SID it's not that easy because the + // version.h is not included with the official package) + bfd_vma vma = section->vma; + unsigned long address = (unsigned long)(info->m_addr); if ( address < vma ) return; - - bfd_size_type size = bfd_section_size(abfd, section); + + // bfd_section_size changed between the two objects described above, + // same rationale applies + bfd_size_type size = section->size; if ( address > (vma + size)) return ; - + const SymbolInfo *pthis = info->m_pthis ; info->m_is_found = bfd_find_nearest_line( abfd, section, pthis->m_impl->m_symbols, @@ -149,7 +156,7 @@ void SymbolInfo::PrintTrace( void *addr, std::ostream& os, std::size_t idx ) { this, addr, 0, 0, 0, false } ; - + Dl_info sym ; bfd_map_over_sections( m_impl->m_bfd, &SymbolInfo::BacktraceInfo::Callback, @@ -165,7 +172,7 @@ if ( btinfo.m_is_found ) filename.erase( pos, std::strlen( SRC_DIR ) ) ; #endif os << "#" << idx << " " << addr << " " - << filename << ":" << btinfo.m_lineno + << filename << ":" << btinfo.m_lineno << " " << (btinfo.m_func_name != 0 ? Demangle(btinfo.m_func_name) : "" ) << std::endl ; From 6aeec257789ceb41c3caa19a095469488c0e85d3 Mon Sep 17 00:00:00 2001 From: Daniel Deptford Date: Sun, 19 Jan 2020 20:03:44 -0800 Subject: [PATCH 55/83] Adding CMake's Backtrace package to resolve issue where the project fails to compile under BSD. --- libgrive/CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libgrive/CMakeLists.txt b/libgrive/CMakeLists.txt index c7ad3cb5..63b2a506 100644 --- a/libgrive/CMakeLists.txt +++ b/libgrive/CMakeLists.txt @@ -4,6 +4,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") find_package(LibGcrypt REQUIRED) find_package(CURL REQUIRED) +find_package(Backtrace) find_package(Boost 1.40.0 COMPONENTS program_options filesystem unit_test_framework regex system REQUIRED) find_package(BFD) find_package(CppUnit) @@ -19,15 +20,15 @@ IF ( CPPUNIT_FOUND ) set( OPT_INCS ${CPPUNIT_INCLUDE_DIR} ) ENDIF ( CPPUNIT_FOUND ) -# build bfd classes if libbfd is found -if ( BFD_FOUND ) - set( OPT_LIBS ${DL_LIBRARY} ${BFD_LIBRARY} ) +# build bfd classes if libbfd and the backtrace library is found +if ( BFD_FOUND AND Backtrace_FOUND ) + set( OPT_LIBS ${DL_LIBRARY} ${BFD_LIBRARY} ${Backtrace_LIBRARY} ) file( GLOB OPT_SRC src/bfd/*.cc ) add_definitions( -DHAVE_BFD ) -endif ( BFD_FOUND ) +endif ( BFD_FOUND AND Backtrace_FOUND ) if ( IBERTY_FOUND ) set( OPT_LIBS ${OPT_LIBS} ${IBERTY_LIBRARY} ) From dc1946498d33f8ce87423fda827a655a2bd1a6f8 Mon Sep 17 00:00:00 2001 From: lmmamercy Date: Wed, 5 Feb 2020 14:30:34 +0000 Subject: [PATCH 56/83] fix ubuntu/debian suggested dependencies --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 43b78cd3..c84fd6ce 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ There are also some optional dependencies: On a Debian/Ubuntu/Linux Mint machine just run the following command to install all these packages: - sudo apt-get install git cmake build-essential libgcrypt11-dev libyajl-dev \ + sudo apt-get install git cmake build-essential libgcrypt20-dev libyajl-dev \ libboost-all-dev libcurl4-openssl-dev libexpat1-dev libcppunit-dev binutils-dev \ debhelper zlib1g-dev dpkg-dev pkg-config From 7b42e2da5bd01eeb74b112597d06f7a5cbed0b04 Mon Sep 17 00:00:00 2001 From: Michael Bartlett Date: Tue, 3 Mar 2020 13:34:27 -0700 Subject: [PATCH 57/83] fix systemd-escape hyphen usage --- systemd/grive-sync.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemd/grive-sync.sh b/systemd/grive-sync.sh index bb837ba3..92b3f6e5 100755 --- a/systemd/grive-sync.sh +++ b/systemd/grive-sync.sh @@ -15,7 +15,7 @@ cd ~ ### ARGUMENT PARSING ### SCRIPT="${0}" -DIRECTORY=$(systemd-escape --unescape "$2") +DIRECTORY=$(systemd-escape --unescape -- "$2") if [[ -z "$DIRECTORY" ]] || [[ ! -d "$DIRECTORY" ]] ; then echo "Need a directory name in the current users home directory as second argument. Aborting." From 97a97265fd801ffa18d289bb14eca84412a01755 Mon Sep 17 00:00:00 2001 From: crborga Date: Tue, 7 Apr 2020 21:35:28 -0400 Subject: [PATCH 58/83] Support Debian 10 Added support for building on Debian 10 without installing gcc7. --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index bd66c5f7..b5fd7bc1 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: grive2 Section: net Priority: optional Maintainer: Vitaliy Filippov -Build-Depends: debhelper, cmake, pkg-config, zlib1g-dev, libcurl4-openssl-dev | libcurl4-gnutls-dev, libstdc++-7-dev |libstdc++-6-dev | libstdc++6-4.4-dev | libstdc++-4.9-dev | libstdc++-5-dev, libboost-filesystem-dev, libboost-program-options-dev, libboost-test-dev, libboost-regex-dev, libexpat1-dev, binutils-dev, libgcrypt-dev, libyajl-dev +Build-Depends: debhelper, cmake, pkg-config, zlib1g-dev, libcurl4-openssl-dev | libcurl4-gnutls-dev, libstdc++-8-dev | libstdc++-7-dev | libstdc++-6-dev | libstdc++6-4.4-dev | libstdc++-4.9-dev | libstdc++-5-dev, libboost-filesystem-dev, libboost-program-options-dev, libboost-test-dev, libboost-regex-dev, libexpat1-dev, binutils-dev, libgcrypt-dev, libyajl-dev Standards-Version: 3.9.6 Homepage: https://yourcmc.ru/wiki/Grive2 From a8b84930f93e9144f7c3d017ba689b3263169e93 Mon Sep 17 00:00:00 2001 From: Agustin Alexander Date: Wed, 23 Sep 2020 19:32:04 -0300 Subject: [PATCH 59/83] Optimized image size (compressed) 214MB -> 62MB --- Dockerfile | 60 +++++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/Dockerfile b/Dockerfile index a63abffb..5ff60c38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,28 @@ -FROM ubuntu:16.04 - -RUN apt-get update && \ - apt-get install --yes --no-install-recommends g++ cmake build-essential \ - libgcrypt11-dev libyajl-dev libboost-all-dev \ - libcurl4-openssl-dev libexpat1-dev libcppunit-dev \ - binutils-dev pkg-config zlib1g-dev && \ - rm -rf /var/cache/apt/archives /var/lib/apt/lists/* - -ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /usr/local/bin/dumb-init - -RUN chmod +x /usr/local/bin/dumb-init - -ADD . /grive2 - -RUN cd /grive2 && \ - mkdir build && \ - cd build && \ - cmake .. && \ - make -j4 && \ - mv /grive2/build/grive/grive /usr/local/bin/grive && \ - rm -rf /grive2 - -VOLUME /data - -WORKDIR /data - -ENTRYPOINT ["dumb-init", "/usr/local/bin/grive"] - - -# docker build -t grive2 . -# docker run --name grive2 --rm -it -v $PWD:/data grive2:latest \ No newline at end of file +FROM alpine:3.7 as build + +RUN apk add git make cmake g++ libgcrypt-dev yajl-dev yajl \ + boost-dev curl-dev expat-dev cppunit-dev binutils-dev \ + pkgconfig \ + && git clone https://github.com/vitalif/grive2.git \ + && mkdir grive2/build \ + && cd grive2/build \ + && cmake .. \ + && make -j4 \ + && make install \ + && cd ../.. \ + && rm -rf grive2 \ + && mkdir /drive + +FROM alpine:3.7 +COPY --from=build /usr/local/bin/grive /bin/grive +COPY ./entrypoint.sh /root/entrypoint.sh +ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /bin/dumb-init +RUN chmod 777 /root/entrypoint.sh /bin/dumb-init /bin/grive \ + && mkdir /drive \ + && apk add yajl-dev curl-dev libgcrypt \ + boost-program_options boost-regex libstdc++ boost-system boost-dev binutils-dev \ + && apk add boost-filesystem --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main +VOLUME /drive +WORKDIR /drive +ENTRYPOINT ["dumb-init", "--"] +CMD ["/root/entrypoint.sh"] From c7a949deddefe52574a336ff9f4833f7d44a3bf4 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Mon, 3 Dec 2018 21:46:52 +0100 Subject: [PATCH 60/83] Revert "Exclude symlinks from sync" This reverts commit b47dd70f35ff74362c7094a55123a1be2618e5be. This could trigger a infinite loop between the timer unit (running a sync and changing the griveignore file at the start) and the changes unit (reacting to the griveignore change and retriggering the sync). --- systemd/grive-sync.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/systemd/grive-sync.sh b/systemd/grive-sync.sh index bb837ba3..8e48670c 100755 --- a/systemd/grive-sync.sh +++ b/systemd/grive-sync.sh @@ -79,12 +79,6 @@ sync_directory() { while [[ "${TIME_AT_START}" -lt "${TIME_AT_END}" ]]; do echo "Syncing "${_directory}"..." TIME_AT_START="$(stat -c %Y "$LOCKFILE")" - # exclude symlinks from sync - cat "${_directory}"/.griveignore 2>/dev/null | sed '/#LINKS-EDIT_BEFORE_THIS$/,$d' > /tmp/.griveignore.base - cp /tmp/.griveignore.base "${_directory}"/.griveignore - rm /tmp/.griveignore.base - echo "#LINKS-EDIT_BEFORE_THIS" >> "${_directory}"/.griveignore - ( cd "${_directory}" && find . -type l | sed 's/^.\///g'; ) >> "${_directory}"/.griveignore grive -p "${_directory}" 2>&1 | grep -v -E "^Reading local directories$|^Reading remote server file list$|^Synchronizing files$|^Finished!$" TIME_AT_END="$(stat -c %Y "$LOCKFILE")" echo "Sync of "${_directory}" done." From 1bab757298506277a8d382c4c74644389c5e7c65 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Wed, 5 Dec 2018 00:02:41 +0100 Subject: [PATCH 61/83] Add systemd unit to enable both timer and changes based syncs Now it's enough to enable and start `grive@.service`. --- README.md | 13 ++++++++----- systemd/CMakeLists.txt | 1 + systemd/grive-timer@.service.in | 2 +- systemd/grive@.service | 13 +++++++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 systemd/grive@.service diff --git a/README.md b/README.md index acb07ca0..35eee2a3 100644 --- a/README.md +++ b/README.md @@ -90,15 +90,18 @@ Prepare a Google Drive folder in your $HOME directory with `grive -a`. ```bash # 'google-drive' is the name of your Google Drive folder in your $HOME directory -systemctl --user enable grive-timer@$(systemd-escape google-drive).timer -systemctl --user start grive-timer@$(systemd-escape google-drive).timer -systemctl --user enable grive-changes@$(systemd-escape google-drive).service -systemctl --user start grive-changes@$(systemd-escape google-drive).service +systemctl --user enable grive@$(systemd-escape google-drive).service +systemctl --user start grive@$(systemd-escape google-drive).service ``` -You can enable and start these two units for multiple folders in your `$HOME` +You can enable and start this unit for multiple folders in your `$HOME` directory if you need to sync with multiple google accounts. +You can also only enable the time based syncing or the changes based syncing +by only directly enabling and starting the corresponding unit: +`grive-changes@$(systemd-escape google-drive).service` or +`grive-timer@$(systemd-escape google-drive).timer`. + ### Shared files Files and folders which are shared with you don't automatically show up in diff --git a/systemd/CMakeLists.txt b/systemd/CMakeLists.txt index e3e57baf..d10322b4 100644 --- a/systemd/CMakeLists.txt +++ b/systemd/CMakeLists.txt @@ -5,6 +5,7 @@ CONFIGURE_FILE(grive-timer@.service.in grive-timer@.service @ONLY) install( FILES + grive@.service ${CMAKE_BINARY_DIR}/systemd/grive-changes@.service ${CMAKE_BINARY_DIR}/systemd/grive-timer@.service DESTINATION diff --git a/systemd/grive-timer@.service.in b/systemd/grive-timer@.service.in index a6aae6ab..d37070f0 100644 --- a/systemd/grive-timer@.service.in +++ b/systemd/grive-timer@.service.in @@ -1,5 +1,5 @@ [Unit] -Description=Google drive sync +Description=Google drive sync (executed by timer unit) After=network-online.target [Service] diff --git a/systemd/grive@.service b/systemd/grive@.service new file mode 100644 index 00000000..e3372db8 --- /dev/null +++ b/systemd/grive@.service @@ -0,0 +1,13 @@ +[Unit] +Description=Google drive sync (main) +Requires=grive-timer@%i.timer grive-changes@%i.service + +# dummy service +[Service] +Type=oneshot +ExecStart=/bin/true +# This service shall be considered active after start +RemainAfterExit=yes + +[Install] +WantedBy=default.target From d7008b81c1d9ec8fa2249d038e96aac2b6adeab5 Mon Sep 17 00:00:00 2001 From: Jan Katins Date: Sun, 14 Mar 2021 22:55:36 +0100 Subject: [PATCH 62/83] Remove uneeded binutils-dev depency --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index b5fd7bc1..b9c97577 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: grive2 Section: net Priority: optional Maintainer: Vitaliy Filippov -Build-Depends: debhelper, cmake, pkg-config, zlib1g-dev, libcurl4-openssl-dev | libcurl4-gnutls-dev, libstdc++-8-dev | libstdc++-7-dev | libstdc++-6-dev | libstdc++6-4.4-dev | libstdc++-4.9-dev | libstdc++-5-dev, libboost-filesystem-dev, libboost-program-options-dev, libboost-test-dev, libboost-regex-dev, libexpat1-dev, binutils-dev, libgcrypt-dev, libyajl-dev +Build-Depends: debhelper, cmake, pkg-config, zlib1g-dev, libcurl4-openssl-dev | libcurl4-gnutls-dev, libstdc++-8-dev | libstdc++-7-dev | libstdc++-6-dev | libstdc++6-4.4-dev | libstdc++-4.9-dev | libstdc++-5-dev, libboost-filesystem-dev, libboost-program-options-dev, libboost-test-dev, libboost-regex-dev, libexpat1-dev, libgcrypt-dev, libyajl-dev Standards-Version: 3.9.6 Homepage: https://yourcmc.ru/wiki/Grive2 From 0b53b08f57f8cff6f9f029c13ca696bc0a88be77 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Thu, 29 Nov 2018 15:25:00 +0100 Subject: [PATCH 63/83] Increment version for debian package and add some changes there * Updated debhelper compat level to latest stable one --- debian/changelog | 4 +++- debian/compat | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index db47f06e..09ac2908 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,8 @@ -grive2 (0.5.1+git20160731) unstable; urgency=medium +grive2 (0.5.2+git20210315) unstable; urgency=medium * Newer dev version + * Add systemd unit files and helper script for automatic syncs + * Add possibility to change client id and secret and save it between runs -- Vitaliy Filippov Wed, 31 Jul 2016 22:04:53 +0300 diff --git a/debian/compat b/debian/compat index 7f8f011e..b4de3947 100644 --- a/debian/compat +++ b/debian/compat @@ -1 +1 @@ -7 +11 From 378df2867b291b03687749e326ad20aed682e9ab Mon Sep 17 00:00:00 2001 From: Jan Katins Date: Mon, 15 Mar 2021 13:30:46 +0100 Subject: [PATCH 64/83] Do explicit unlocks in grive-sync.sh script --- systemd/grive-sync.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/systemd/grive-sync.sh b/systemd/grive-sync.sh index bb837ba3..5d32296c 100755 --- a/systemd/grive-sync.sh +++ b/systemd/grive-sync.sh @@ -62,18 +62,20 @@ unlock() { _lock u; } # drop a lock sync_directory() { _directory="${1}" + + reset_timer_and_exit() { echo "Retriggered google drive sync" && touch -m $LOCKFILE && exit; } + + exlock_now || reset_timer_and_exit + if ping -c1 -W1 -q accounts.google.com >/dev/null 2>&1; then true # pass else - echo "Google drive server not reachable..." + echo "Google drive server not reachable, NOT syncing..." + unlock exit 0 fi - reset_timer_and_exit() { echo "Retriggered google drive sync" && touch -m "$LOCKFILE" && exit; } - - exlock_now || reset_timer_and_exit - TIME_AT_START=0 TIME_AT_END=1 while [[ "${TIME_AT_START}" -lt "${TIME_AT_END}" ]]; do @@ -91,10 +93,11 @@ sync_directory() { done # always exit ok, so that we never go into a wrong systemd state + unlock exit 0 } -### LISTEN TO DIRECTORY CHANGES ### +### LISTEN TO CHANGES IN DIRECTORY ### listen_directory() { From 4dfc9a546182f5acffcdfd652bd4ffb2e29cccec Mon Sep 17 00:00:00 2001 From: Jan Katins Date: Mon, 15 Mar 2021 13:40:52 +0100 Subject: [PATCH 65/83] Install grive-sync.sh into the right libdir --- systemd/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/systemd/CMakeLists.txt b/systemd/CMakeLists.txt index d10322b4..bd6ac924 100644 --- a/systemd/CMakeLists.txt +++ b/systemd/CMakeLists.txt @@ -1,4 +1,4 @@ -SET(GRIVE_SYNC_SH_BINARY "${CMAKE_INSTALL_PREFIX}/lib/grive/grive-sync.sh") +SET(GRIVE_SYNC_SH_BINARY "${CMAKE_INSTALL_FULL_LIBDIR}/grive/grive-sync.sh") CONFIGURE_FILE(grive-changes@.service.in grive-changes@.service @ONLY) CONFIGURE_FILE(grive-timer@.service.in grive-timer@.service @ONLY) @@ -23,5 +23,5 @@ install( PROGRAMS grive-sync.sh DESTINATION - lib/grive + ${CMAKE_INSTALL_FULL_LIBDIR}/grive ) \ No newline at end of file From 5510ca1b0635dd96e6d688603eac07a1318acbef Mon Sep 17 00:00:00 2001 From: Jan Katins Date: Mon, 15 Mar 2021 14:24:36 +0100 Subject: [PATCH 66/83] More consistent directory name output in logs --- systemd/grive-sync.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/systemd/grive-sync.sh b/systemd/grive-sync.sh index 5d32296c..23ee92bb 100755 --- a/systemd/grive-sync.sh +++ b/systemd/grive-sync.sh @@ -63,7 +63,7 @@ unlock() { _lock u; } # drop a lock sync_directory() { _directory="${1}" - reset_timer_and_exit() { echo "Retriggered google drive sync" && touch -m $LOCKFILE && exit; } + reset_timer_and_exit() { echo "Retriggered google drive sync ('${_directory}')" && touch -m $LOCKFILE && exit; } exlock_now || reset_timer_and_exit @@ -79,7 +79,7 @@ sync_directory() { TIME_AT_START=0 TIME_AT_END=1 while [[ "${TIME_AT_START}" -lt "${TIME_AT_END}" ]]; do - echo "Syncing "${_directory}"..." + echo "Syncing '${_directory}'..." TIME_AT_START="$(stat -c %Y "$LOCKFILE")" # exclude symlinks from sync cat "${_directory}"/.griveignore 2>/dev/null | sed '/#LINKS-EDIT_BEFORE_THIS$/,$d' > /tmp/.griveignore.base @@ -89,7 +89,7 @@ sync_directory() { ( cd "${_directory}" && find . -type l | sed 's/^.\///g'; ) >> "${_directory}"/.griveignore grive -p "${_directory}" 2>&1 | grep -v -E "^Reading local directories$|^Reading remote server file list$|^Synchronizing files$|^Finished!$" TIME_AT_END="$(stat -c %Y "$LOCKFILE")" - echo "Sync of "${_directory}" done." + echo "Sync of '${_directory}' done." done # always exit ok, so that we never go into a wrong systemd state @@ -105,7 +105,7 @@ listen_directory() { type inotifywait >/dev/null 2>&1 || { echo >&2 "I require inotifywait but it's not installed. Aborting."; exit 1; } - echo "Listening for changes in ~/"${_directory}"" + echo "Listening for changes in '${_directory}'" while true #run indefinitely do From e0965f7fb8ef5e99afdd851af9000318592d22c1 Mon Sep 17 00:00:00 2001 From: Jan Katins Date: Tue, 16 Mar 2021 21:36:26 +0100 Subject: [PATCH 67/83] Remove the libstdc++ dependency These are included in the right version via the suggested installation of build-essential, which which installs the right lib via dependencies: g++ -> g++- -> libstdc++- Adding it explicitly meant always adding new versions :-( --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index b9c97577..150f6883 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: grive2 Section: net Priority: optional Maintainer: Vitaliy Filippov -Build-Depends: debhelper, cmake, pkg-config, zlib1g-dev, libcurl4-openssl-dev | libcurl4-gnutls-dev, libstdc++-8-dev | libstdc++-7-dev | libstdc++-6-dev | libstdc++6-4.4-dev | libstdc++-4.9-dev | libstdc++-5-dev, libboost-filesystem-dev, libboost-program-options-dev, libboost-test-dev, libboost-regex-dev, libexpat1-dev, libgcrypt-dev, libyajl-dev +Build-Depends: debhelper, cmake, pkg-config, zlib1g-dev, libcurl4-openssl-dev | libcurl4-gnutls-dev, libboost-filesystem-dev, libboost-program-options-dev, libboost-test-dev, libboost-regex-dev, libexpat1-dev, libgcrypt-dev, libyajl-dev Standards-Version: 3.9.6 Homepage: https://yourcmc.ru/wiki/Grive2 From 27ca714e565da9f6959ceefd1bd657f96e245fc0 Mon Sep 17 00:00:00 2001 From: Jan Katins Date: Thu, 18 Mar 2021 10:34:15 +0100 Subject: [PATCH 68/83] Add .idea folder to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index b33b2e27..de247d2f 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ debian/grive/ debian/.debhelper obj-x86_64-linux-gnu/ + +.idea From 9076e3aed22400e408e4d0e9ecf2cb5d16719a85 Mon Sep 17 00:00:00 2001 From: Jan Katins Date: Tue, 23 Mar 2021 18:10:10 +0100 Subject: [PATCH 69/83] Ensure that the systemd files get installed in debian If you build in pbuilder, no systemd is installed and so the flag is set to false which means the files will not get installed. Adding the explicit flag will make sure they are included in the package. --- debian/rules | 3 +++ 1 file changed, 3 insertions(+) diff --git a/debian/rules b/debian/rules index 61596921..6f9c7a78 100755 --- a/debian/rules +++ b/debian/rules @@ -1,4 +1,7 @@ #!/usr/bin/make -f +override_dh_auto_configure: + dh_auto_configure -- -DHAVE_SYSTEMD=1 + %: dh $@ --buildsystem=cmake --parallel --builddirectory=build From 050fcf53a07d99822a7de186d7f4e4a0be209903 Mon Sep 17 00:00:00 2001 From: Jan Katins Date: Tue, 30 Mar 2021 15:19:53 +0200 Subject: [PATCH 70/83] Move helper script into libexec dir This seems to be a proper dir for such "not-for-normal-user" things... --- systemd/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/systemd/CMakeLists.txt b/systemd/CMakeLists.txt index bd6ac924..6de3e454 100644 --- a/systemd/CMakeLists.txt +++ b/systemd/CMakeLists.txt @@ -1,4 +1,4 @@ -SET(GRIVE_SYNC_SH_BINARY "${CMAKE_INSTALL_FULL_LIBDIR}/grive/grive-sync.sh") +SET(GRIVE_SYNC_SH_BINARY "${CMAKE_INSTALL_FULL_LIBEXECDIR}/grive/grive-sync.sh") CONFIGURE_FILE(grive-changes@.service.in grive-changes@.service @ONLY) CONFIGURE_FILE(grive-timer@.service.in grive-timer@.service @ONLY) @@ -24,4 +24,4 @@ install( grive-sync.sh DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/grive -) \ No newline at end of file +) From 814b724cc466d4bb7ae7548c43c586d8cb71973f Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Thu, 15 Apr 2021 12:41:10 +0200 Subject: [PATCH 71/83] Handle NetBSD like macOS for timestamp precision. --- libgrive/src/util/OS.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libgrive/src/util/OS.cc b/libgrive/src/util/OS.cc index e8b468fd..7c5fa70b 100644 --- a/libgrive/src/util/OS.cc +++ b/libgrive/src/util/OS.cc @@ -59,7 +59,7 @@ void Stat( const std::string& filename, DateTime *t, off64_t *size, FileType *ft if ( t ) { -#if defined __APPLE__ && defined __DARWIN_64_BIT_INO_T +#if defined __NetBSD__ || ( defined __APPLE__ && defined __DARWIN_64_BIT_INO_T ) *t = DateTime( s.st_ctimespec.tv_sec, s.st_ctimespec.tv_nsec ) ; #else *t = DateTime( s.st_ctim.tv_sec, s.st_ctim.tv_nsec); From 30763e2f9dac0ddd19a7c5bf272a556d5c3af17d Mon Sep 17 00:00:00 2001 From: Thomas Klausner Date: Thu, 15 Apr 2021 12:41:40 +0200 Subject: [PATCH 72/83] Add compatibility define for off64_t. Not all systems define off64_t. --- libgrive/src/util/OS.hh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libgrive/src/util/OS.hh b/libgrive/src/util/OS.hh index bd28e30d..3fe89b8b 100644 --- a/libgrive/src/util/OS.hh +++ b/libgrive/src/util/OS.hh @@ -31,6 +31,10 @@ class Path ; enum FileType { FT_FILE = 1, FT_DIR = 2, FT_UNKNOWN = 3 } ; +#ifndef off64_t +#define off64_t off_t +#endif + namespace os { struct Error : virtual Exception {} ; From 03a2c58403d00805d2883eaeb923e390ed111cfe Mon Sep 17 00:00:00 2001 From: Agustin Alexander Date: Fri, 14 May 2021 13:47:14 -0300 Subject: [PATCH 73/83] Fix Dockerfile --- Dockerfile | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5ff60c38..8c39e824 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,14 +15,13 @@ RUN apk add git make cmake g++ libgcrypt-dev yajl-dev yajl \ FROM alpine:3.7 COPY --from=build /usr/local/bin/grive /bin/grive -COPY ./entrypoint.sh /root/entrypoint.sh ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /bin/dumb-init -RUN chmod 777 /root/entrypoint.sh /bin/dumb-init /bin/grive \ - && mkdir /drive \ +RUN chmod 777 /bin/dumb-init /bin/grive \ + && mkdir /data \ && apk add yajl-dev curl-dev libgcrypt \ boost-program_options boost-regex libstdc++ boost-system boost-dev binutils-dev \ && apk add boost-filesystem --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main -VOLUME /drive -WORKDIR /drive -ENTRYPOINT ["dumb-init", "--"] -CMD ["/root/entrypoint.sh"] + +VOLUME /data +WORKDIR /data +ENTRYPOINT ["dumb-init", "grive"] From 48f5f0e52f87b35f9f77987c8a699dab48ff9256 Mon Sep 17 00:00:00 2001 From: ncaq Date: Thu, 8 Jul 2021 14:37:13 +0900 Subject: [PATCH 74/83] fixed: CMAKE_INSTALL_FULL_LIBDIR -> CMAKE_INSTALL_FULL_LIBEXECDIR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because, It must equal GRIVE_SYNC_SH_BINARY and actual grive-sync.sh path. I patched my gentoo overlay ebuild. [added: grive: libexec patch ยท ncaq/ncaq-overlay@ed3354f](https://github.com/ncaq/ncaq-overlay/commit/ed3354fbb704b78cfc5a1779036ce444fde40933) --- systemd/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemd/CMakeLists.txt b/systemd/CMakeLists.txt index 6de3e454..36d6d22a 100644 --- a/systemd/CMakeLists.txt +++ b/systemd/CMakeLists.txt @@ -23,5 +23,5 @@ install( PROGRAMS grive-sync.sh DESTINATION - ${CMAKE_INSTALL_FULL_LIBDIR}/grive + ${CMAKE_INSTALL_FULL_LIBEXECDIR}/grive ) From 3cf1c058a3e61deb370dde36024a106a213ab2c6 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Sat, 21 May 2022 09:36:52 -0600 Subject: [PATCH 75/83] Syncer.hh: fix build with gcc-12 --- libgrive/src/base/Syncer.hh | 1 + 1 file changed, 1 insertion(+) diff --git a/libgrive/src/base/Syncer.hh b/libgrive/src/base/Syncer.hh index 237b8949..9b6ae4f7 100644 --- a/libgrive/src/base/Syncer.hh +++ b/libgrive/src/base/Syncer.hh @@ -21,6 +21,7 @@ #include "util/FileSystem.hh" +#include #include #include #include From 5c8e87ee9a201123bbab30e1a238f7e67fa9ff0a Mon Sep 17 00:00:00 2001 From: Jasper Young Date: Tue, 20 Sep 2022 20:10:28 -0400 Subject: [PATCH 76/83] Fix CMake CMP0004 Error --- cmake/Modules/FindLibGcrypt.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/Modules/FindLibGcrypt.cmake b/cmake/Modules/FindLibGcrypt.cmake index 0e1727f2..1cbc10a0 100644 --- a/cmake/Modules/FindLibGcrypt.cmake +++ b/cmake/Modules/FindLibGcrypt.cmake @@ -27,6 +27,9 @@ IF(LIBGCRYPTCONFIG_EXECUTABLE) EXEC_PROGRAM(${LIBGCRYPTCONFIG_EXECUTABLE} ARGS --cflags RETURN_VALUE _return_VALUE OUTPUT_VARIABLE LIBGCRYPT_CFLAGS) + string(REPLACE "fgrep: warning: fgrep is obsolescent; using grep -F" "" LIBGCRYPT_LIBRARIES "${LIBGCRYPT_LIBRARIES}") + string(STRIP "${LIBGCRYPT_LIBRARIES}" LIBGCRYPT_LIBRARIES) + IF(${LIBGCRYPT_CFLAGS} MATCHES "\n") SET(LIBGCRYPT_CFLAGS " ") ENDIF(${LIBGCRYPT_CFLAGS} MATCHES "\n") From 6645206d2733e0fe74573b1a90680204eb3cb57b Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Wed, 9 Nov 2022 12:37:10 +0300 Subject: [PATCH 77/83] Implement Google OAuth loopback IP address flow (fixes #362 #372 #365) --- grive/src/main.cc | 34 ++++----- libgrive/src/protocol/OAuth2.cc | 127 +++++++++++++++++++++++++++++++- libgrive/src/protocol/OAuth2.hh | 8 +- libgrive/src/util/Config.cc | 2 +- 4 files changed, 146 insertions(+), 25 deletions(-) diff --git a/grive/src/main.cc b/grive/src/main.cc index 54d5560b..8009d121 100644 --- a/grive/src/main.cc +++ b/grive/src/main.cc @@ -111,9 +111,9 @@ int Main( int argc, char **argv ) ( "help,h", "Produce help message" ) ( "version,v", "Display Grive version" ) ( "auth,a", "Request authorization token" ) - ( "id,i", po::value(), "Authentication ID") - ( "secret,e", po::value(), "Authentication secret") - ( "print-url", "Only print url for request") + ( "id,i", po::value(), "Authentication ID") + ( "secret,e", po::value(), "Authentication secret") + ( "print-url", "Only print url for request") ( "path,p", po::value(), "Path to working copy root") ( "dir,s", po::value(), "Single subdirectory to sync") ( "verbose,V", "Verbose mode. Enable more messages than normal.") @@ -185,34 +185,32 @@ int Main( int argc, char **argv ) : default_secret ; OAuth2 token( http.get(), id, secret ) ; - + if ( vm.count("print-url") ) { - std::cout << token.MakeAuthURL() << std::endl ; + std::cout << token.MakeAuthURL() << std::endl ; return 0 ; } - + std::cout << "-----------------------\n" - << "Please go to this URL and get an authentication code:\n\n" + << "Please open this URL in your browser to authenticate Grive2:\n\n" << token.MakeAuthURL() << std::endl ; - - std::cout - << "\n-----------------------\n" - << "Please input the authentication code here: " << std::endl ; - std::string code ; - std::cin >> code ; - - token.Auth( code ) ; - + + if ( !token.GetCode() ) + { + std::cout << "Authentication failed\n"; + return -1; + } + // save to config config.Set( "id", Val( id ) ) ; config.Set( "secret", Val( secret ) ) ; config.Set( "refresh_token", Val( token.RefreshToken() ) ) ; config.Save() ; } - + std::string refresh_token ; std::string id ; std::string secret ; @@ -231,7 +229,7 @@ int Main( int argc, char **argv ) return -1; } - + OAuth2 token( http.get(), refresh_token, id, secret ) ; AuthAgent agent( token, http.get() ) ; v2::Syncer2 syncer( &agent ); diff --git a/libgrive/src/protocol/OAuth2.cc b/libgrive/src/protocol/OAuth2.cc index db1858aa..478f1082 100644 --- a/libgrive/src/protocol/OAuth2.cc +++ b/libgrive/src/protocol/OAuth2.cc @@ -25,6 +25,13 @@ #include "http/Header.hh" #include "util/log/Log.hh" +#include +#include +#include +#include +#include +#include + // for debugging #include @@ -50,18 +57,29 @@ OAuth2::OAuth2( const std::string& client_id, const std::string& client_secret ) : m_agent( agent ), + m_port( 0 ), + m_socket( -1 ), m_client_id( client_id ), m_client_secret( client_secret ) { } -void OAuth2::Auth( const std::string& auth_code ) +OAuth2::~OAuth2() +{ + if ( m_socket >= 0 ) + { + close( m_socket ); + m_socket = -1; + } +} + +bool OAuth2::Auth( const std::string& auth_code ) { std::string post = "code=" + auth_code + "&client_id=" + m_client_id + "&client_secret=" + m_client_secret + - "&redirect_uri=" + "urn:ietf:wg:oauth:2.0:oob" + + "&redirect_uri=http%3A%2F%2Flocalhost:" + std::to_string( m_port ) + "%2Fauth" + "&grant_type=authorization_code" ; http::ValResponse resp ; @@ -77,19 +95,120 @@ void OAuth2::Auth( const std::string& auth_code ) { Log( "Failed to obtain auth token: HTTP %1%, body: %2%", code, m_agent->LastError(), log::error ) ; - BOOST_THROW_EXCEPTION( AuthFailed() ); + return false; } + + return true; } std::string OAuth2::MakeAuthURL() { + if ( !m_port ) + { + sockaddr_storage addr = { 0 }; + addr.ss_family = AF_INET; + m_socket = socket( AF_INET, SOCK_STREAM, 0 ); + if ( m_socket < 0 ) + throw std::runtime_error( std::string("socket: ") + strerror(errno) ); + if ( bind( m_socket, (sockaddr*)&addr, sizeof( addr ) ) < 0 ) + { + close( m_socket ); + m_socket = -1; + throw std::runtime_error( std::string("bind: ") + strerror(errno) ); + } + socklen_t len = sizeof( addr ); + if ( getsockname( m_socket, (sockaddr *)&addr, &len ) == -1 ) + { + close( m_socket ); + m_socket = -1; + throw std::runtime_error( std::string("getsockname: ") + strerror(errno) ); + } + m_port = ntohs(((sockaddr_in*)&addr)->sin_port); + if ( listen( m_socket, 128 ) < 0 ) + { + close( m_socket ); + m_socket = -1; + m_port = 0; + throw std::runtime_error( std::string("listen: ") + strerror(errno) ); + } + } return "https://accounts.google.com/o/oauth2/auth" "?scope=" + m_agent->Escape( "https://www.googleapis.com/auth/drive" ) + - "&redirect_uri=urn:ietf:wg:oauth:2.0:oob" + "&redirect_uri=http%3A%2F%2Flocalhost:" + std::to_string( m_port ) + "%2Fauth" + "&response_type=code" "&client_id=" + m_client_id ; } +bool OAuth2::GetCode( ) +{ + sockaddr_storage addr = { 0 }; + int peer_fd = -1; + while ( peer_fd < 0 ) + { + socklen_t peer_addr_size = sizeof( addr ); + peer_fd = accept( m_socket, (sockaddr*)&addr, &peer_addr_size ); + if ( peer_fd == -1 && errno != EAGAIN && errno != EINTR ) + throw std::runtime_error( std::string("accept: ") + strerror(errno) ); + } + fcntl( peer_fd, F_SETFL, fcntl( peer_fd, F_GETFL, 0 ) | O_NONBLOCK ); + struct pollfd pfd = (struct pollfd){ + .fd = peer_fd, + .events = POLLIN|POLLRDHUP, + }; + char buf[4096]; + std::string request; + while ( true ) + { + pfd.revents = 0; + poll( &pfd, 1, -1 ); + if ( pfd.revents & POLLRDHUP ) + break; + int r = 1; + while ( r > 0 ) + { + r = read( peer_fd, buf, sizeof( buf ) ); + if ( r > 0 ) + request += std::string( buf, r ); + else if ( r == 0 ) + break; + else if ( errno != EAGAIN && errno != EINTR ) + throw std::runtime_error( std::string("read: ") + strerror(errno) ); + } + if ( r == 0 || ( r < 0 && request.find( "\n" ) > 0 ) ) // GET ... HTTP/1.1\r\n + break; + } + bool ok = false; + if ( request.substr( 0, 10 ) == "GET /auth?" ) + { + std::string line = request; + int p = line.find( "\n" ); + if ( p > 0 ) + line = line.substr( 0, p ); + p = line.rfind( " " ); + if ( p > 0 ) + line = line.substr( 0, p ); + p = line.find( "code=" ); + if ( p > 0 ) + line = line.substr( p+5 ); + p = line.find( "&" ); + if ( p > 0 ) + line = line.substr( 0, p ); + ok = Auth( line ); + } + std::string response = ( ok + ? "Authenticated successfully. Please close the page" + : "Authentication error. Please try again" ); + response = "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html; charset=utf-8\r\n" + "Connection: close\r\n" + "\r\n"+ + response+ + "\r\n"; + write( peer_fd, response.c_str(), response.size() ); + close( peer_fd ); + return ok; +} + void OAuth2::Refresh( ) { std::string post = diff --git a/libgrive/src/protocol/OAuth2.hh b/libgrive/src/protocol/OAuth2.hh index e9a23dae..ae40db75 100644 --- a/libgrive/src/protocol/OAuth2.hh +++ b/libgrive/src/protocol/OAuth2.hh @@ -41,13 +41,15 @@ public : const std::string& refresh_code, const std::string& client_id, const std::string& client_secret ) ; + ~OAuth2( ) ; std::string Str() const ; std::string MakeAuthURL() ; - void Auth( const std::string& auth_code ) ; + bool Auth( const std::string& auth_code ) ; void Refresh( ) ; + bool GetCode( ) ; std::string RefreshToken( ) const ; std::string AccessToken( ) const ; @@ -59,7 +61,9 @@ private : std::string m_access ; std::string m_refresh ; http::Agent* m_agent ; - + int m_port ; + int m_socket ; + const std::string m_client_id ; const std::string m_client_secret ; } ; diff --git a/libgrive/src/util/Config.cc b/libgrive/src/util/Config.cc index c08972f6..7d17a55d 100644 --- a/libgrive/src/util/Config.cc +++ b/libgrive/src/util/Config.cc @@ -84,7 +84,7 @@ void Config::Save( ) void Config::Set( const std::string& key, const Val& value ) { - m_file.Add( key, value ) ; + m_file.Set( key, value ) ; } Val Config::Get( const std::string& key ) const From 328987ec34030af09b246d9d54b882bd174ad0cb Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Wed, 9 Nov 2022 12:41:47 +0300 Subject: [PATCH 78/83] Fix readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 35eee2a3..9924965c 100644 --- a/README.md +++ b/README.md @@ -39,10 +39,10 @@ grive -a A URL should be printed. Go to the link. You will need to login to your Google account if you haven't done so. After granting the permission to Grive, the -browser will show you an authenication code. Copy-and-paste that to the -standard input of Grive. +authorization code will be forwarded to the Grive application and you will be +redirected to a localhost web page confirming the authorization. -If everything works fine, Grive will create .grive and .grive_state files in your +If everything works fine, Grive will create .grive and .grive\_state files in your current directory. It will also start downloading files from your Google Drive to your current directory. From d03c4a24ceb179d0fdb4c47e3d144d547ffcc8b6 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Wed, 9 Nov 2022 12:45:14 +0300 Subject: [PATCH 79/83] Bump version to 0.5.3 --- CMakeLists.txt | 2 +- README.md | 9 ++++++--- debian/changelog | 7 +++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d716609..5bf001a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(grive2) include(GNUInstallDirs) # Grive version. remember to update it for every new release! -set( GRIVE_VERSION "0.5.2-dev" CACHE STRING "Grive version" ) +set( GRIVE_VERSION "0.5.3" CACHE STRING "Grive version" ) message(WARNING "Version to build: ${GRIVE_VERSION}") # common compile options diff --git a/README.md b/README.md index 9924965c..a71923d1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Grive2 0.5.2-dev +# Grive2 0.5.3 -13 Nov 2019, Vitaliy Filippov +09 Nov 2022, Vitaliy Filippov http://yourcmc.ru/wiki/Grive2 @@ -203,7 +203,10 @@ Alternativly you can define your own client_id and client_secret during build ## Version History -### Grive2 v0.5.2-dev +### Grive2 v0.5.3 + +- Implement Google OAuth loopback IP redirect flow +- Various small fixes ### Grive2 v0.5.1 diff --git a/debian/changelog b/debian/changelog index 09ac2908..0910281d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +grive2 (0.5.3) unstable; urgency=medium + + * Implement Google OAuth loopback IP redirect flow + * Various small fixes + + -- Vitaliy Filippov Wed, 09 Nov 2022 12:42:28 +0300 + grive2 (0.5.2+git20210315) unstable; urgency=medium * Newer dev version From cd4665ae1b417321d22e44acbf1933aa5fa467d3 Mon Sep 17 00:00:00 2001 From: Kilian von Pflugk Date: Sun, 17 Apr 2022 01:38:45 +0200 Subject: [PATCH 80/83] reduce docker image size even more --- .dockerignore | 5 +---- Dockerfile | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.dockerignore b/.dockerignore index 4b218551..f59ec20a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1 @@ -.git -Dockerfile -.dockerignore -.gitignore +* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8c39e824..124fb2d0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM alpine:3.7 as build RUN apk add git make cmake g++ libgcrypt-dev yajl-dev yajl \ - boost-dev curl-dev expat-dev cppunit-dev binutils-dev \ + boost-dev curl-dev expat-dev cppunit-dev binutils-dev \ pkgconfig \ && git clone https://github.com/vitalif/grive2.git \ && mkdir grive2/build \ @@ -9,7 +9,7 @@ RUN apk add git make cmake g++ libgcrypt-dev yajl-dev yajl \ && cmake .. \ && make -j4 \ && make install \ - && cd ../.. \ + && cd ../.. \ && rm -rf grive2 \ && mkdir /drive @@ -18,8 +18,8 @@ COPY --from=build /usr/local/bin/grive /bin/grive ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /bin/dumb-init RUN chmod 777 /bin/dumb-init /bin/grive \ && mkdir /data \ - && apk add yajl-dev curl-dev libgcrypt \ - boost-program_options boost-regex libstdc++ boost-system boost-dev binutils-dev \ + && apk add yajl libcurl libgcrypt \ + boost-program_options boost-regex libstdc++ boost-system boost binutils \ && apk add boost-filesystem --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main VOLUME /data From b788284020ed93cc5cf9d263aeb6d285d15b91e0 Mon Sep 17 00:00:00 2001 From: Christoph Junghans Date: Sat, 21 May 2022 09:36:52 -0600 Subject: [PATCH 81/83] Syncer.hh: fix build with gcc-12 --- libgrive/src/base/Syncer.hh | 1 + 1 file changed, 1 insertion(+) diff --git a/libgrive/src/base/Syncer.hh b/libgrive/src/base/Syncer.hh index 237b8949..9b6ae4f7 100644 --- a/libgrive/src/base/Syncer.hh +++ b/libgrive/src/base/Syncer.hh @@ -21,6 +21,7 @@ #include "util/FileSystem.hh" +#include #include #include #include From 648ff8eea1a3c7cac8bfba283f75717bf54c67eb Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 10 Dec 2022 13:20:39 +0300 Subject: [PATCH 82/83] Cache layers during Docker build, take source from the current dir instead of cloning --- .dockerignore | 6 +++++- Dockerfile | 34 ++++++++++++++++------------------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.dockerignore b/.dockerignore index f59ec20a..34a7f7e9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,5 @@ -* \ No newline at end of file +* +!cmake +!grive +!libgrive +!CMakeLists.txt diff --git a/Dockerfile b/Dockerfile index 124fb2d0..ee0ee1b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,25 @@ FROM alpine:3.7 as build -RUN apk add git make cmake g++ libgcrypt-dev yajl-dev yajl \ +RUN apk add make cmake g++ libgcrypt-dev yajl-dev yajl \ boost-dev curl-dev expat-dev cppunit-dev binutils-dev \ - pkgconfig \ - && git clone https://github.com/vitalif/grive2.git \ - && mkdir grive2/build \ - && cd grive2/build \ - && cmake .. \ - && make -j4 \ - && make install \ - && cd ../.. \ - && rm -rf grive2 \ - && mkdir /drive + pkgconfig + +ADD . /grive2 + +RUN mkdir /grive2/build \ + && cd /grive2/build \ + && cmake .. \ + && make -j4 install FROM alpine:3.7 -COPY --from=build /usr/local/bin/grive /bin/grive -ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /bin/dumb-init -RUN chmod 777 /bin/dumb-init /bin/grive \ - && mkdir /data \ - && apk add yajl libcurl libgcrypt \ - boost-program_options boost-regex libstdc++ boost-system boost binutils \ + +RUN apk add yajl libcurl libgcrypt boost-program_options boost-regex libstdc++ boost-system \ && apk add boost-filesystem --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main +COPY --from=build /usr/local/bin/grive /bin/grive +RUN chmod 777 /bin/grive \ + && mkdir /data + VOLUME /data WORKDIR /data -ENTRYPOINT ["dumb-init", "grive"] +ENTRYPOINT grive From be52cb21a7ea5c16db0d5f3b22f1864629ff36ae Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Fri, 26 Jul 2024 18:55:50 +0300 Subject: [PATCH 83/83] Remove libdl build requirement --- cmake/Modules/FindBFD.cmake | 10 ++-------- libgrive/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/cmake/Modules/FindBFD.cmake b/cmake/Modules/FindBFD.cmake index 35dfd5d6..8fd4427b 100644 --- a/cmake/Modules/FindBFD.cmake +++ b/cmake/Modules/FindBFD.cmake @@ -1,12 +1,6 @@ -find_library( DL_LIBRARY NAMES dl PATH ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ) find_library( BFD_LIBRARY NAMES bfd PATH ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES} ) -if ( DL_LIBRARY AND BFD_LIBRARY ) +if ( BFD_LIBRARY ) set( BFD_FOUND TRUE ) -endif (DL_LIBRARY AND BFD_LIBRARY) - -if ( BFD_FOUND ) - message( STATUS "Found libbfd: ${BFD_LIBRARY}") - -endif ( BFD_FOUND ) +endif ( BFD_LIBRARY ) diff --git a/libgrive/CMakeLists.txt b/libgrive/CMakeLists.txt index 63b2a506..c56d70cf 100644 --- a/libgrive/CMakeLists.txt +++ b/libgrive/CMakeLists.txt @@ -22,7 +22,7 @@ ENDIF ( CPPUNIT_FOUND ) # build bfd classes if libbfd and the backtrace library is found if ( BFD_FOUND AND Backtrace_FOUND ) - set( OPT_LIBS ${DL_LIBRARY} ${BFD_LIBRARY} ${Backtrace_LIBRARY} ) + set( OPT_LIBS ${BFD_LIBRARY} ${Backtrace_LIBRARY} ) file( GLOB OPT_SRC src/bfd/*.cc )