From 9c43ad9cc94ae5d0761538fa88488321e95996e8 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 12 Dec 2015 17:16:05 +0300 Subject: [PATCH] Internally convert -s option to ignore regexp. Fixes #49, should fix #42. --- libgrive/src/base/State.cc | 24 +++++++++++++++--------- libgrive/src/base/State.hh | 1 - 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/libgrive/src/base/State.cc b/libgrive/src/base/State.cc index 00f1728..1f79e3d 100644 --- a/libgrive/src/base/State.cc +++ b/libgrive/src/base/State.cc @@ -35,7 +35,6 @@ namespace gr { State::State( const fs::path& filename, const Val& options ) : m_res ( options["path"].Str() ), - m_dir ( options["dir"].Str() ), m_cstamp ( -1 ) { Read( filename ) ; @@ -49,6 +48,20 @@ State::State( const fs::path& filename, const Val& options ) : m_ign = options["ignore"].Str(); force = true; } + else if ( options.Has( "dir" ) ) + { + const boost::regex trim_path( "^/+|/+$" ); + std::string m_dir = regex_replace( options["dir"].Str(), trim_path, "" ); + if ( !m_dir.empty() ) + { + // "-s" is internally converted to an ignore regexp + 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_ign = ign; + } + } // the "-f" option will make grive always think remote is newer if ( force ) @@ -95,10 +108,6 @@ void State::FromLocal( const fs::path& p, Resource* folder ) if ( IsIgnore( path ) ) Log( "file %1% is ignored by grive", path, log::verbose ) ; - // check if it is ignored - else if ( folder == m_res.Root() && m_dir != "" && fname != m_dir ) - Log( "%1% %2% is ignored", st.type() == fs::directory_file ? "folder" : "file", fname, log::verbose ); - // check for broken symblic links else if ( st.type() == fs::file_not_found ) Log( "file %1% doesn't exist (broken link?), ignored", i->path(), log::verbose ) ; @@ -129,11 +138,8 @@ void State::FromRemote( const Entry& e ) std::string fn = e.Filename() ; std::string k = e.IsDir() ? "folder" : "file"; - if ( e.ParentHref() == m_res.Root()->SelfHref() && m_dir != "" && e.Name() != m_dir ) - Log( "%1% %2% is ignored", k, e.Name(), log::verbose ); - // common checkings - else if ( !e.IsDir() && (fn.empty() || e.ContentSrc().empty()) ) + if ( !e.IsDir() && (fn.empty() || e.ContentSrc().empty()) ) Log( "%1% \"%2%\" is a google document, ignored", k, e.Name(), log::verbose ) ; else if ( fn.find('/') != fn.npos ) diff --git a/libgrive/src/base/State.hh b/libgrive/src/base/State.hh index 8df66d4..d972802 100644 --- a/libgrive/src/base/State.hh +++ b/libgrive/src/base/State.hh @@ -78,7 +78,6 @@ private : DateTime m_last_sync ; DateTime m_last_change ; int m_cstamp ; - std::string m_dir ; std::string m_ign ; boost::regex m_ign_re ;