mirror of https://github.com/vitalif/grive2
Do not track last_sync at all, clear srv_time's with -f option
parent
8f640ebdad
commit
23fa985bdb
|
@ -1,7 +1,7 @@
|
||||||
cmake_minimum_required(VERSION 2.8)
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
|
||||||
# Grive version. remember to update it for every new release!
|
# Grive version. remember to update it for every new release!
|
||||||
set( GRIVE_VERSION "0.4.2" )
|
set( GRIVE_VERSION "0.5-pre" )
|
||||||
|
|
||||||
# common compile options
|
# common compile options
|
||||||
add_definitions( -DVERSION="${GRIVE_VERSION}" )
|
add_definitions( -DVERSION="${GRIVE_VERSION}" )
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Grive2 0.4.2
|
# Grive2 0.5-dev
|
||||||
|
|
||||||
28 Dec 2015, Vitaliy Filippov
|
02 Jan 2016, Vitaliy Filippov
|
||||||
|
|
||||||
http://yourcmc.ru/wiki/Grive2
|
http://yourcmc.ru/wiki/Grive2
|
||||||
|
|
||||||
|
@ -70,6 +70,11 @@ Enjoy!
|
||||||
|
|
||||||
## Version History
|
## Version History
|
||||||
|
|
||||||
|
### Grive2 v0.5 (unreleased)
|
||||||
|
|
||||||
|
- Much faster and more correct synchronisation using local modification time and checksum cache (similar to git index)
|
||||||
|
- force option works again
|
||||||
|
|
||||||
### Grive2 v0.4.2
|
### Grive2 v0.4.2
|
||||||
|
|
||||||
- Option to exclude files by perl regexp
|
- Option to exclude files by perl regexp
|
||||||
|
|
|
@ -38,14 +38,15 @@ State::State( const fs::path& filename, const Val& options ) :
|
||||||
{
|
{
|
||||||
Read( filename ) ;
|
Read( filename ) ;
|
||||||
|
|
||||||
bool force = options.Has( "force" ) ? options["force"].Bool() : false ;
|
// the "-f" option will make grive always think remote is newer
|
||||||
|
m_force = options.Has( "force" ) ? options["force"].Bool() : false ;
|
||||||
|
|
||||||
if ( options.Has( "ignore" ) && options["ignore"].Str() != m_ign )
|
if ( options.Has( "ignore" ) && options["ignore"].Str() != m_ign )
|
||||||
{
|
{
|
||||||
// also "-f" is implicitly turned on when ignore regexp is changed
|
// also "-f" is implicitly turned on when ignore regexp is changed
|
||||||
// because without it grive would think that previously ignored files are deleted locally
|
// because without it grive would think that previously ignored files are deleted locally
|
||||||
if ( !m_ign.empty() )
|
if ( !m_ign.empty() )
|
||||||
force = true;
|
m_force = true;
|
||||||
m_ign = options["ignore"].Str();
|
m_ign = options["ignore"].Str();
|
||||||
}
|
}
|
||||||
else if ( options.Has( "dir" ) )
|
else if ( options.Has( "dir" ) )
|
||||||
|
@ -58,18 +59,12 @@ State::State( const fs::path& filename, const Val& options ) :
|
||||||
const boost::regex esc( "[.^$|()\\[\\]{}*+?\\\\]" );
|
const boost::regex esc( "[.^$|()\\[\\]{}*+?\\\\]" );
|
||||||
std::string ign = "^(?!"+regex_replace( m_dir, esc, "\\\\&", boost::format_sed )+"(/|$))";
|
std::string ign = "^(?!"+regex_replace( m_dir, esc, "\\\\&", boost::format_sed )+"(/|$))";
|
||||||
if ( !m_ign.empty() && ign != m_ign )
|
if ( !m_ign.empty() && ign != m_ign )
|
||||||
force = true;
|
m_force = true;
|
||||||
m_ign = ign;
|
m_ign = ign;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the "-f" option will make grive always think remote is newer
|
|
||||||
if ( force )
|
|
||||||
m_last_sync = DateTime() ;
|
|
||||||
|
|
||||||
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)" ) );
|
||||||
|
|
||||||
Log( "last sync time: %2%", m_last_sync, log::verbose ) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
State::~State()
|
State::~State()
|
||||||
|
@ -80,8 +75,6 @@ State::~State()
|
||||||
/// of local directory.
|
/// of local directory.
|
||||||
void State::FromLocal( const fs::path& p )
|
void State::FromLocal( const fs::path& p )
|
||||||
{
|
{
|
||||||
// Remember m_update_sync just before reading local file tree
|
|
||||||
m_update_sync = DateTime::Now() ;
|
|
||||||
m_res.Root()->FromLocal( m_st ) ;
|
m_res.Root()->FromLocal( m_st ) ;
|
||||||
FromLocal( p, m_res.Root(), m_st.Item( "tree" ) ) ;
|
FromLocal( p, m_res.Root(), m_st.Item( "tree" ) ) ;
|
||||||
}
|
}
|
||||||
|
@ -118,6 +111,8 @@ void State::FromLocal( const fs::path& p, Resource* folder, Val& tree )
|
||||||
}
|
}
|
||||||
leftover.erase( fname );
|
leftover.erase( fname );
|
||||||
Val& rec = tree.Item( fname );
|
Val& rec = tree.Item( fname );
|
||||||
|
if ( m_force )
|
||||||
|
rec.Del( "srv_time" );
|
||||||
c->FromLocal( rec ) ;
|
c->FromLocal( rec ) ;
|
||||||
if ( c->IsFolder() )
|
if ( c->IsFolder() )
|
||||||
FromLocal( *i, c, rec.Item( "tree" ) ) ;
|
FromLocal( *i, c, rec.Item( "tree" ) ) ;
|
||||||
|
@ -134,7 +129,10 @@ void State::FromLocal( const fs::path& p, Resource* folder, Val& tree )
|
||||||
folder->AddChild( c ) ;
|
folder->AddChild( c ) ;
|
||||||
m_res.Insert( c ) ;
|
m_res.Insert( c ) ;
|
||||||
}
|
}
|
||||||
c->FromDeleted( tree.Item( i->first ) );
|
Val& rec = tree.Item( i->first );
|
||||||
|
if ( m_force )
|
||||||
|
rec.Del( "srv_time" );
|
||||||
|
c->FromDeleted( rec );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,14 +269,11 @@ State::iterator State::end()
|
||||||
|
|
||||||
void State::Read( const fs::path& filename )
|
void State::Read( const fs::path& filename )
|
||||||
{
|
{
|
||||||
m_last_sync.Assign( 0 ) ;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File file( filename ) ;
|
File file( filename ) ;
|
||||||
|
|
||||||
m_st = ParseJson( file );
|
m_st = ParseJson( file );
|
||||||
Val last_sync = m_st["last_sync"] ;
|
|
||||||
m_last_sync.Assign( last_sync["sec"].Int(), last_sync["nsec"].Int() ) ;
|
|
||||||
m_ign = m_st.Has( "ignore_regexp" ) ? m_st["ignore_regexp"].Str() : std::string();
|
m_ign = m_st.Has( "ignore_regexp" ) ? m_st["ignore_regexp"].Str() : std::string();
|
||||||
|
|
||||||
m_cstamp = m_st["change_stamp"].Int() ;
|
m_cstamp = m_st["change_stamp"].Int() ;
|
||||||
|
@ -290,11 +285,6 @@ void State::Read( const fs::path& filename )
|
||||||
|
|
||||||
void State::Write( const fs::path& filename )
|
void State::Write( const fs::path& filename )
|
||||||
{
|
{
|
||||||
Val last_sync ;
|
|
||||||
last_sync.Add( "sec", Val( (int)m_last_sync.Sec() ) );
|
|
||||||
last_sync.Add( "nsec", Val( (unsigned)m_last_sync.NanoSec() ) );
|
|
||||||
|
|
||||||
m_st.Set( "last_sync", last_sync ) ;
|
|
||||||
m_st.Set( "change_stamp", Val( m_cstamp ) ) ;
|
m_st.Set( "change_stamp", Val( m_cstamp ) ) ;
|
||||||
m_st.Set( "ignore_regexp", Val( m_ign ) ) ;
|
m_st.Set( "ignore_regexp", Val( m_ign ) ) ;
|
||||||
|
|
||||||
|
@ -306,7 +296,6 @@ void State::Sync( Syncer *syncer, const Val& options )
|
||||||
{
|
{
|
||||||
// set the last sync time to the time on the client
|
// set the last sync time to the time on the client
|
||||||
m_res.Root()->Sync( syncer, options ) ;
|
m_res.Root()->Sync( syncer, options ) ;
|
||||||
m_last_sync = m_update_sync;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long State::ChangeStamp() const
|
long State::ChangeStamp() const
|
||||||
|
|
|
@ -74,12 +74,11 @@ private :
|
||||||
|
|
||||||
private :
|
private :
|
||||||
ResourceTree m_res ;
|
ResourceTree m_res ;
|
||||||
DateTime m_last_sync ;
|
|
||||||
DateTime m_update_sync ;
|
|
||||||
int m_cstamp ;
|
int m_cstamp ;
|
||||||
std::string m_ign ;
|
std::string m_ign ;
|
||||||
boost::regex m_ign_re ;
|
boost::regex m_ign_re ;
|
||||||
Val m_st ;
|
Val m_st ;
|
||||||
|
bool m_force ;
|
||||||
|
|
||||||
std::vector<Entry> m_unresolved ;
|
std::vector<Entry> m_unresolved ;
|
||||||
} ;
|
} ;
|
||||||
|
|
Loading…
Reference in New Issue