diff --git a/README.md b/README.md index ce32d50..afde8e1 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,10 @@ Enjoy! ## Version History +### Grive2 v0.5.1-dev + +- no-remote-new and upload-only modes + ### Grive2 v0.5 - Much faster and more correct synchronisation using local modification time and checksum cache (similar to git index) diff --git a/grive/doc/grive.1 b/grive/doc/grive.1 index 96efbff..ad9ea0d 100644 --- a/grive/doc/grive.1 +++ b/grive/doc/grive.1 @@ -33,6 +33,16 @@ Forces .I grive to always download a file from Google Drive instead uploading it .TP +\fB\-u, \-\-upload\-only\fR +Forces +.I grive +to not download anything from Google Drive and only upload local changes to server instead +.TP +\fB\-n, \-\-no\-remote\-new\fR +Forces +.I grive +to download only files that are changed in Google Drive and already exist locally +.TP \fB\-h\fR, \fB\-\-help\fR Produces help message .TP diff --git a/grive/src/main.cc b/grive/src/main.cc index b0fb4ae..6038313 100644 --- a/grive/src/main.cc +++ b/grive/src/main.cc @@ -118,6 +118,8 @@ int Main( int argc, char **argv ) ( "log,l", po::value(), "Set log output filename." ) ( "force,f", "Force grive to always download a file from Google Drive " "instead of uploading it." ) + ( "upload-only,u", "Do not download anything from Google Drive, only upload local changes" ) + ( "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, remembered for next runs)." ) diff --git a/libgrive/src/base/Resource.cc b/libgrive/src/base/Resource.cc index 8fc67a9..9cc441e 100644 --- a/libgrive/src/base/Resource.cc +++ b/libgrive/src/base/Resource.cc @@ -542,26 +542,36 @@ void Resource::SyncSelf( Syncer* syncer, ResourceTree *res_tree, const Val& opti break ; case remote_new : - Log( "sync %1% created in remote. creating local", path, log::info ) ; - if ( syncer ) + if ( options["no-remote-new"].Bool() ) + Log( "sync %1% created in remote. skipping", path, log::info ) ; + else { - if ( IsFolder() ) - fs::create_directories( path ) ; - else - syncer->Download( this, path ) ; - SetIndex( true ) ; - m_state = sync ; + Log( "sync %1% created in remote. creating local", path, log::info ) ; + if ( syncer ) + { + if ( IsFolder() ) + fs::create_directories( path ) ; + else + syncer->Download( this, path ) ; + SetIndex( true ) ; + m_state = sync ; + } } break ; case remote_changed : assert( !IsFolder() ) ; - Log( "sync %1% changed in remote. downloading", path, log::info ) ; - if ( syncer ) + if ( options["upload-only"].Bool() ) + Log( "sync %1% changed in remote. skipping", path, log::info ) ; + else { - syncer->Download( this, path ) ; - SetIndex( true ) ; - m_state = sync ; + Log( "sync %1% changed in remote. downloading", path, log::info ) ; + if ( syncer ) + { + syncer->Download( this, path ) ; + SetIndex( true ) ; + m_state = sync ; + } } break ; diff --git a/libgrive/src/util/Config.cc b/libgrive/src/util/Config.cc index b8483c8..4d03108 100644 --- a/libgrive/src/util/Config.cc +++ b/libgrive/src/util/Config.cc @@ -46,8 +46,10 @@ Config::Config( const po::variables_map& vm ) m_cmd.Add( "dir", Val(vm.count("dir") > 0 ? vm["dir"].as() : "" ) ) ; - if ( vm.count("ignore") > 0 ) + if ( vm.count( "ignore" ) > 0 ) m_cmd.Add( "ignore", Val( vm["ignore"].as() ) ); + m_cmd.Add( "no-remote-new", Val( vm.count( "no-remote-new" ) > 0 || vm.count( "upload-only" ) > 0 ) ); + m_cmd.Add( "upload-only", Val( vm.count( "upload-only" ) > 0 ) ); m_path = GetPath( fs::path(m_cmd["path"].Str()) ) ; m_file = Read( ) ;