Skip to content

Commit

Permalink
Implement upload-only and no-remote-new modes (fix #69)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed May 9, 2016
1 parent cfb8ff0 commit 40e33cb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions grive/doc/grive.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions grive/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ int Main( int argc, char **argv )
( "log,l", po::value<std::string>(), "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<std::string>(), "Perl RegExp to ignore files (matched against relative paths, remembered for next runs)." )
Expand Down
36 changes: 23 additions & 13 deletions libgrive/src/base/Resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;

Expand Down
4 changes: 3 additions & 1 deletion libgrive/src/util/Config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ Config::Config( const po::variables_map& vm )
m_cmd.Add( "dir", Val(vm.count("dir") > 0
? vm["dir"].as<std::string>()
: "" ) ) ;
if ( vm.count("ignore") > 0 )
if ( vm.count( "ignore" ) > 0 )
m_cmd.Add( "ignore", Val( vm["ignore"].as<std::string>() ) );
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( ) ;
Expand Down

0 comments on commit 40e33cb

Please sign in to comment.