You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by al...@apache.org on 2016/09/15 18:03:43 UTC

nifi-minifi-cpp git commit: MINIFI-103 added File Filter Property to GetFile processor

Repository: nifi-minifi-cpp
Updated Branches:
  refs/heads/master cadd945d9 -> eb1f268fb


MINIFI-103 added File Filter Property to GetFile processor

This closes #11.

Signed-off-by: Aldrin Piri <al...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/commit/eb1f268f
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/eb1f268f
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/eb1f268f

Branch: refs/heads/master
Commit: eb1f268fb05556a8467a97b4f54fe2f9c1e09b45
Parents: cadd945
Author: Jeremy Dyer <jd...@gmail.com>
Authored: Fri Sep 9 09:19:38 2016 -0400
Committer: Aldrin Piri <al...@apache.org>
Committed: Thu Sep 15 14:02:57 2016 -0400

----------------------------------------------------------------------
 inc/GetFile.h   |  3 +++
 src/GetFile.cpp | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/eb1f268f/inc/GetFile.h
----------------------------------------------------------------------
diff --git a/inc/GetFile.h b/inc/GetFile.h
index 7ba6af4..eb975fd 100644
--- a/inc/GetFile.h
+++ b/inc/GetFile.h
@@ -47,6 +47,7 @@ public:
 		_pollInterval = 0;
 		_batchSize = 10;
 		_lastDirectoryListingTime = getTimeMillis();
+		_fileFilter = "[^\\.].*";
 	}
 	//! Destructor
 	virtual ~GetFile()
@@ -65,6 +66,7 @@ public:
 	static Property IgnoreHiddenFile;
 	static Property PollInterval;
 	static Property BatchSize;
+	static Property FileFilter;
 	//! Supported Relationships
 	static Relationship Success;
 
@@ -109,6 +111,7 @@ private:
 	int64_t _pollInterval;
 	int64_t _batchSize;
 	uint64_t _lastDirectoryListingTime;
+	std::string _fileFilter;
 };
 
 #endif

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/eb1f268f/src/GetFile.cpp
----------------------------------------------------------------------
diff --git a/src/GetFile.cpp b/src/GetFile.cpp
index 32503f5..02e196a 100644
--- a/src/GetFile.cpp
+++ b/src/GetFile.cpp
@@ -32,6 +32,7 @@
 #include <dirent.h>
 #include <limits.h>
 #include <unistd.h>
+#include <regex>
 
 #include "TimeUtil.h"
 #include "GetFile.h"
@@ -52,6 +53,7 @@ Property GetFile::MaxSize("Maximum File Size", "The maximum size that a file can
 Property GetFile::MinSize("Minimum File Size", "The minimum size that a file must be in order to be pulled", "0 B");
 Property GetFile::PollInterval("Polling Interval", "Indicates how long to wait before performing a directory listing", "0 sec");
 Property GetFile::Recurse("Recurse Subdirectories", "Indicates whether or not to pull files from subdirectories", "true");
+Property GetFile::FileFilter("File Filter", "Only files whose names match the given regular expression will be picked up", "[^\\.].*");
 Relationship GetFile::Success("success", "All files are routed to success");
 
 void GetFile::initialize()
@@ -68,6 +70,7 @@ void GetFile::initialize()
 	properties.insert(MinSize);
 	properties.insert(PollInterval);
 	properties.insert(Recurse);
+	properties.insert(FileFilter);
 	setSupportedProperties(properties);
 	//! Set the supported relationships
 	std::set<Relationship> relationships;
@@ -134,6 +137,11 @@ void GetFile::onTrigger(ProcessContext *context, ProcessSession *session)
 		Property::StringToBool(value, _recursive);
 	}
 
+	if (context->getProperty(FileFilter.getName(), value))
+	{
+		_fileFilter = value;
+	}
+
 	// Perform directory list
 	if (isListingEmpty())
 	{
@@ -235,6 +243,16 @@ bool GetFile::acceptFile(std::string fileName)
 		if (_keepSourceFile == false && access(fileName.c_str(), W_OK) != 0)
 			return false;
 
+		try {
+			std::regex re(_fileFilter);
+			if (!std::regex_match(fileName, re)) {
+				return false;
+	   		}
+		} catch (std::regex_error e) {
+			_logger->log_error("Invalid File Filter regex: %s.", e.what());
+			return false;
+		}
+
 		return true;
 	}