Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

A small patch to use the boost regex library to filter filenames #108

Closed
wants to merge 1 commit into from

4 participants

@mianos

I did this as I need to synchronise a filesystem with dotted files in it.
Files to ignore are specified using a perl regular expression in State.cc
The regex is compiled a static initialisation time.
My first use of github and a pull request so apologies in advance is this is messed up.
Feel free to suggest a better place to put the expression.

@nestal
Owner

Thanks for the patch!

I am not sure the advantage of using regex to filter out the dot file.

Some users has suggested to add user-defined regex filters (something like .gitignore) to tell Grive to ignore certain files. Are you interested to work on that?

@mianos
@funkyfuture

i agree that one file in the root would be simpler. but having the possibilty to define rules per path at some point would make it more flexible and larger rulesets easier to maintain.
though i have to admit it's certainly no top priority issue as it propably would affect only few users.

@dnschneid

Regex is overkill; the below patch works just as well (and filters out the exact same set of files). But really, the ignore function should also require the absolute path so that only the exact grive files are filtered out. On the other hand, I'm taking advantage of the .grive* filtering to stick extra non-syncing things (like sync logs) in the same folder...

---
 libgrive/src/drive/State.cc |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libgrive/src/drive/State.cc b/libgrive/src/drive/State.cc
index 43e6367..1dbb822 100644
--- a/libgrive/src/drive/State.cc
+++ b/libgrive/src/drive/State.cc
@@ -59,7 +59,11 @@ void State::FromLocal( const fs::path& p )

 bool State::IsIgnore( const std::string& filename )
 {
-   return filename[0] == '.' ;
+   if ( filename.length() < 6 )
+       return false ;
+
+   return filename[0] == '.' && filename[1] == 'g' && filename[2] == 'r' &&
+          filename[3] == 'i' && filename[4] == 'v' && filename[5] == 'e' ;
 }

 void State::FromLocal( const fs::path& p, gr::Resource* folder )
-- 
1.7.9.5
@mianos mianos closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 28, 2012
  1. @mianos
This page is out of date. Refresh to see the latest.
View
2  libgrive/CMakeLists.txt
@@ -6,7 +6,7 @@ find_package(LibGcrypt REQUIRED)
find_package(JSONC REQUIRED)
find_package(CURL REQUIRED)
find_package(EXPAT REQUIRED)
-find_package(Boost 1.40.0 COMPONENTS filesystem system REQUIRED)
+find_package(Boost 1.40.0 COMPONENTS filesystem system regex REQUIRED)
find_package(BFD)
find_package(CppUnit)
find_package(Iberty)
View
6 libgrive/src/drive/State.cc
@@ -29,9 +29,12 @@
#include "protocol/Json.hh"
#include <fstream>
+#include <boost/regex.hpp>
namespace gr {
+boost::regex State::m_rexp = boost::regex("(\\.|\\.\\.|\\.grive.*)");
+
State::State( const fs::path& filename, const Json& options ) :
m_cstamp( -1 )
{
@@ -56,9 +59,10 @@ void State::FromLocal( const fs::path& p )
FromLocal( p, m_res.Root() ) ;
}
+// changed to only ignore
bool State::IsIgnore( const std::string& filename )
{
- return filename[0] == '.' ;
+ return boost::regex_match(filename, m_rexp);
}
void State::FromLocal( const fs::path& p, gr::Resource* folder )
View
3  libgrive/src/drive/State.hh
@@ -25,6 +25,7 @@
#include "util/FileSystem.hh"
#include <memory>
+#include <boost/regex.hpp>
namespace gr {
@@ -79,6 +80,8 @@ private :
long m_cstamp ;
std::vector<Entry> m_unresolved ;
+ static boost::regex m_rexp ;
} ;
+
} // end of namespace
Something went wrong with that request. Please try again.