diff -Nru grive2-0.5.1/debian/changelog grive2-0.5.1/debian/changelog --- grive2-0.5.1/debian/changelog 2016-10-13 12:04:33.000000000 +0000 +++ grive2-0.5.1/debian/changelog 2017-03-22 16:03:44.000000000 +0000 @@ -1,4 +1,16 @@ -grive2 (0.5.1-1+git20161013~webupd8~vivid0) vivid; urgency=medium +grive2 (0.5.1-1+git20170322~webupd8~vivid0) vivid; urgency=medium + + * New git pull + + -- Alin Andrei Wed, 22 Mar 2017 18:03:44 +0200 + +grive2 (0.5.1-1+git20170320~webupd8~trusty0) trusty; urgency=medium + + * new git pull + + -- Alin Andrei Mon, 20 Mar 2017 11:40:29 +0200 + +grive2 (0.5.1-1+git20161013~webupd8~yakkety0) yakkety; urgency=medium * new git pull diff -Nru grive2-0.5.1/grive/doc/grive.1 grive2-0.5.1/grive/doc/grive.1 --- grive2-0.5.1/grive/doc/grive.1 2016-10-04 09:25:24.000000000 +0000 +++ grive2-0.5.1/grive/doc/grive.1 2017-03-20 09:39:57.000000000 +0000 @@ -46,10 +46,6 @@ \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 @@ \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 -Nru grive2-0.5.1/grive/src/main.cc grive2-0.5.1/grive/src/main.cc --- grive2-0.5.1/grive/src/main.cc 2016-10-04 09:25:24.000000000 +0000 +++ grive2-0.5.1/grive/src/main.cc 2017-03-20 09:39:57.000000000 +0000 @@ -124,15 +124,22 @@ ( "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 @@ } // initialize logging - InitLog(vm) ; + InitLog( vm ) ; - Config config(vm) ; + Config config( vm ) ; Log( "config file name %1%", config.Filename(), log::verbose ); diff -Nru grive2-0.5.1/libgrive/src/base/Drive.cc grive2-0.5.1/libgrive/src/base/Drive.cc --- grive2-0.5.1/libgrive/src/base/Drive.cc 2016-10-04 09:25:24.000000000 +0000 +++ grive2-0.5.1/libgrive/src/base/Drive.cc 2017-03-20 09:39:57.000000000 +0000 @@ -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::SaveState() { - m_state.Write( m_root / state_file ) ; + m_state.Write() ; } void Drive::DetectChanges() diff -Nru grive2-0.5.1/libgrive/src/base/Resource.cc grive2-0.5.1/libgrive/src/base/Resource.cc --- grive2-0.5.1/libgrive/src/base/Resource.cc 2016-10-04 09:25:24.000000000 +0000 +++ grive2-0.5.1/libgrive/src/base/Resource.cc 2017-03-20 09:39:57.000000000 +0000 @@ -262,10 +262,10 @@ 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 @@ 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 @@ 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 -Nru grive2-0.5.1/libgrive/src/base/State.cc grive2-0.5.1/libgrive/src/base/State.cc --- grive2-0.5.1/libgrive/src/base/State.cc 2016-10-04 09:25:24.000000000 +0000 +++ grive2-0.5.1/libgrive/src/base/State.cc 2017-03-22 16:03:44.000000000 +0000 @@ -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 @@ 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 @@ } 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,91 @@ 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 ) + { + } +} + +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 -Nru grive2-0.5.1/libgrive/src/base/State.hh grive2-0.5.1/libgrive/src/base/State.hh --- grive2-0.5.1/libgrive/src/base/State.hh 2016-10-04 09:25:24.000000000 +0000 +++ grive2-0.5.1/libgrive/src/base/State.hh 2017-03-20 09:39:57.000000000 +0000 @@ -42,15 +42,15 @@ 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 @@ 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 @@ bool IsIgnore( const std::string& filename ) ; private : + fs::path m_root ; ResourceTree m_res ; int m_cstamp ; std::string m_ign ; diff -Nru grive2-0.5.1/libgrive/src/http/CurlAgent.cc grive2-0.5.1/libgrive/src/http/CurlAgent.cc --- grive2-0.5.1/libgrive/src/http/CurlAgent.cc 2016-10-04 09:25:24.000000000 +0000 +++ grive2-0.5.1/libgrive/src/http/CurlAgent.cc 2017-03-20 09:39:57.000000000 +0000 @@ -190,8 +190,10 @@ 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); diff -Nru grive2-0.5.1/libgrive/src/util/OS.cc grive2-0.5.1/libgrive/src/util/OS.cc --- grive2-0.5.1/libgrive/src/util/OS.cc 2016-10-04 09:25:24.000000000 +0000 +++ grive2-0.5.1/libgrive/src/util/OS.cc 2017-03-20 09:39:57.000000000 +0000 @@ -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 @@ ) ; } - 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 @@ } 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 -Nru grive2-0.5.1/libgrive/src/util/OS.hh grive2-0.5.1/libgrive/src/util/OS.hh --- grive2-0.5.1/libgrive/src/util/OS.hh 2016-10-04 09:25:24.000000000 +0000 +++ grive2-0.5.1/libgrive/src/util/OS.hh 2017-03-20 09:39:57.000000000 +0000 @@ -29,12 +29,14 @@ 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 ) ; diff -Nru grive2-0.5.1/README.md grive2-0.5.1/README.md --- grive2-0.5.1/README.md 2016-10-04 09:25:24.000000000 +0000 +++ grive2-0.5.1/README.md 2017-03-20 09:39:57.000000000 +0000 @@ -85,6 +85,7 @@ ### 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 @@ - #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