Skip to content

Commit

Permalink
Make ignore regexp non-persistent (fix #58)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed May 11, 2016
1 parent 62e2611 commit 5327016
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Enjoy!
### Grive2 v0.5.1-dev

- 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)

### Grive2 v0.5

Expand Down
2 changes: 1 addition & 1 deletion libgrive/src/base/Resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ void Resource::SyncSelf( Syncer* syncer, ResourceTree *res_tree, const Val& opti

case local_deleted :
Log( "sync %1% deleted in local. deleting remote", path, log::info ) ;
if ( syncer )
if ( syncer && !options["no-delete-remote"].Bool() )
{
syncer->DeleteRemote( this ) ;
DeleteIndex() ;
Expand Down
31 changes: 20 additions & 11 deletions libgrive/src/base/State.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ State::State( const fs::path& filename, const Val& options ) :
// 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" ) )
Expand All @@ -62,7 +64,8 @@ State::State( const fs::path& filename, const Val& options ) :
m_ign = ign;
}
}


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)" ) );
}

Expand Down Expand Up @@ -120,18 +123,24 @@ void State::FromLocal( const fs::path& p, Resource* folder, Val& tree )

for( Val::Object::iterator i = leftover.begin(); i != leftover.end(); i++ )
{
// Restore state of locally deleted files
Resource *c = folder->FindChild( i->first ) ;
if ( !c )
std::string path = folder->IsRoot() ? i->first : ( folder->RelPath() / i->first ).string();
if ( IsIgnore( path ) )
Log( "file %1% is ignored by grive", path, log::verbose ) ;
else
{
c = new Resource( i->first, i->second.Has( "tree" ) ? "folder" : "file" ) ;
folder->AddChild( c ) ;
m_res.Insert( c ) ;
// Restore state of locally deleted files
Resource *c = folder->FindChild( i->first ) ;
if ( !c )
{
c = new Resource( i->first, i->second.Has( "tree" ) ? "folder" : "file" ) ;
folder->AddChild( c ) ;
m_res.Insert( c ) ;
}
Val& rec = tree.Item( i->first );
if ( m_force || m_ign_changed )
rec.Del( "srv_time" );
c->FromDeleted( rec );
}
Val& rec = tree.Item( i->first );
if ( m_force )
rec.Del( "srv_time" );
c->FromDeleted( rec );
}
}

Expand Down
1 change: 1 addition & 0 deletions libgrive/src/base/State.hh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ private :
boost::regex m_ign_re ;
Val m_st ;
bool m_force ;
bool m_ign_changed ;

std::list<Entry> m_unresolved ;
} ;
Expand Down
1 change: 1 addition & 0 deletions libgrive/src/util/Config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Config::Config( const po::variables_map& vm )
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_cmd.Add( "no-delete-remote", Val( vm.count( "no-delete-remote" ) > 0 ) );

m_path = GetPath( fs::path(m_cmd["path"].Str()) ) ;
m_file = Read( ) ;
Expand Down

0 comments on commit 5327016

Please sign in to comment.