Do not track last_sync at all, clear srv_time's with -f option

syncer-move-dates
Vitaliy Filippov 2016-01-02 15:05:37 +03:00
parent 8f640ebdad
commit 23fa985bdb
4 changed files with 19 additions and 26 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 2.8)
# 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
add_definitions( -DVERSION="${GRIVE_VERSION}" )

View File

@ -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
@ -70,6 +70,11 @@ Enjoy!
## 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
- Option to exclude files by perl regexp

View File

@ -38,14 +38,15 @@ State::State( const fs::path& filename, const Val& options ) :
{
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 )
{
// also "-f" is implicitly turned on when ignore regexp is changed
// because without it grive would think that previously ignored files are deleted locally
if ( !m_ign.empty() )
force = true;
m_force = true;
m_ign = options["ignore"].Str();
}
else if ( options.Has( "dir" ) )
@ -58,18 +59,12 @@ State::State( const fs::path& filename, const Val& options ) :
const boost::regex esc( "[.^$|()\\[\\]{}*+?\\\\]" );
std::string ign = "^(?!"+regex_replace( m_dir, esc, "\\\\&", boost::format_sed )+"(/|$))";
if ( !m_ign.empty() && ign != m_ign )
force = true;
m_force = true;
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)" ) );
Log( "last sync time: %2%", m_last_sync, log::verbose ) ;
}
State::~State()
@ -80,8 +75,6 @@ State::~State()
/// of local directory.
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 ) ;
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 );
Val& rec = tree.Item( fname );
if ( m_force )
rec.Del( "srv_time" );
c->FromLocal( rec ) ;
if ( c->IsFolder() )
FromLocal( *i, c, rec.Item( "tree" ) ) ;
@ -134,7 +129,10 @@ void State::FromLocal( const fs::path& p, Resource* folder, Val& tree )
folder->AddChild( 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 )
{
m_last_sync.Assign( 0 ) ;
try
{
File file( filename ) ;
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_cstamp = m_st["change_stamp"].Int() ;
@ -290,11 +285,6 @@ void State::Read( 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( "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
m_res.Root()->Sync( syncer, options ) ;
m_last_sync = m_update_sync;
}
long State::ChangeStamp() const

View File

@ -74,12 +74,11 @@ private :
private :
ResourceTree m_res ;
DateTime m_last_sync ;
DateTime m_update_sync ;
int m_cstamp ;
std::string m_ign ;
boost::regex m_ign_re ;
Val m_st ;
bool m_force ;
std::vector<Entry> m_unresolved ;
} ;