You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jo...@apache.org on 2014/12/31 20:45:46 UTC

incubator-nifi git commit: NIFI-208 refined logic for identifying files to pull

Repository: incubator-nifi
Updated Branches:
  refs/heads/develop ad90fbf24 -> 3004ff172


NIFI-208 refined logic for identifying files to pull


Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/3004ff17
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/3004ff17
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/3004ff17

Branch: refs/heads/develop
Commit: 3004ff172054e8991e9b66a7c71fabd06f8bbc4c
Parents: ad90fbf
Author: joewitt <jo...@apache.org>
Authored: Wed Dec 31 14:36:42 2014 -0500
Committer: joewitt <jo...@apache.org>
Committed: Wed Dec 31 14:36:42 2014 -0500

----------------------------------------------------------------------
 .../nifi/processors/standard/GetFile.java       | 20 ++++++++++++++++----
 .../index.html                                  |  6 ++++--
 2 files changed, 20 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/3004ff17/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFile.java
----------------------------------------------------------------------
diff --git a/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFile.java b/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFile.java
index 1a1213c..bf4de58 100644
--- a/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFile.java
+++ b/nar-bundles/standard-bundle/standard-processors/src/main/java/org/apache/nifi/processors/standard/GetFile.java
@@ -67,7 +67,7 @@ import org.apache.nifi.processor.util.StandardValidators;
 
 @TriggerWhenEmpty
 @Tags({"local", "files", "filesystem", "ingest", "ingress", "get", "source", "input"})
-@CapabilityDescription("Creates FlowFiles from files in a directory")
+@CapabilityDescription("Creates FlowFiles from files in a directory.  NiFi will ignore files it doesn't have at least read permissions for.")
 public class GetFile extends AbstractProcessor {
 
     public static final PropertyDescriptor DIRECTORY = new PropertyDescriptor.Builder()
@@ -86,7 +86,10 @@ public class GetFile extends AbstractProcessor {
             .build();
     public static final PropertyDescriptor KEEP_SOURCE_FILE = new PropertyDescriptor.Builder()
             .name("Keep Source File")
-            .description("If true, the file is not deleted after it has been copied to the Content Repository; this causes the file to be picked up continually and is useful for testing purposes")
+            .description("If true, the file is not deleted after it has been copied to the Content Repository; "
+                    + "this causes the file to be picked up continually and is useful for testing purposes.  "
+                    + "If not keeping original NiFi will need write permissions on the directory it is pulling "
+                    + "from otherwise it will ignore the file.")
             .required(true)
             .allowableValues("true", "false")
             .defaultValue("false")
@@ -224,6 +227,7 @@ public class GetFile extends AbstractProcessor {
         final boolean recurseDirs = context.getProperty(RECURSE).asBoolean();
         final String pathPatternStr = context.getProperty(PATH_FILTER).getValue();
         final Pattern pathPattern = (!recurseDirs || pathPatternStr == null) ? null : Pattern.compile(pathPatternStr);
+        final boolean keepOriginal = context.getProperty(KEEP_SOURCE_FILE).asBoolean();
 
         return new FileFilter() {
             @Override
@@ -252,6 +256,15 @@ public class GetFile extends AbstractProcessor {
                         }
                     }
                 }
+                //Verify that we have at least read permissions on the file we're considering grabbing
+                if(!Files.isReadable(file.toPath())){
+                    return false;
+                }
+                
+                //Verify that if we're not keeping original that we have write permissions on the directory the file is in
+                if(keepOriginal == false && !Files.isWritable(file.toPath().getParent())){
+                    return false;
+                }
                 return filePattern.matcher(file.getName()).matches();
             }
         };
@@ -375,12 +388,11 @@ public class GetFile extends AbstractProcessor {
         }
 
         final ListIterator<File> itr = files.listIterator();
-        File file = null;
         FlowFile flowFile = null;
         try {
             final Path directoryPath = directory.toPath();
             while (itr.hasNext()) {
-                file = itr.next();
+                final File file = itr.next();
                 final Path filePath = file.toPath();
                 final Path relativePath = directoryPath.relativize(filePath.getParent());
                 String relativePathString = relativePath.toString() + "/";

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/3004ff17/nar-bundles/standard-bundle/standard-processors/src/main/resources/docs/org.apache.nifi.processors.standard.GetFile/index.html
----------------------------------------------------------------------
diff --git a/nar-bundles/standard-bundle/standard-processors/src/main/resources/docs/org.apache.nifi.processors.standard.GetFile/index.html b/nar-bundles/standard-bundle/standard-processors/src/main/resources/docs/org.apache.nifi.processors.standard.GetFile/index.html
index 11a8dfa..9faa128 100644
--- a/nar-bundles/standard-bundle/standard-processors/src/main/resources/docs/org.apache.nifi.processors.standard.GetFile/index.html
+++ b/nar-bundles/standard-bundle/standard-processors/src/main/resources/docs/org.apache.nifi.processors.standard.GetFile/index.html
@@ -23,7 +23,7 @@
     <body>
         <!-- Processor Documentation ================================================== -->
         <h2>Description:</h2>
-        <p>This processor obtains FlowFiles from a local directory.</p>
+        <p>This processor obtains FlowFiles from a local directory.  NiFi will need at least read permissions on the files it will pull otherwise it will ignore them.</p>
 
         <p>
             <strong>Modifies Attributes:</strong>
@@ -105,7 +105,9 @@
                     <li>A Boolean value (true/false), indicating whether to leave a
                         copy of the file in the input directory after retrieving it; this
                         causes the file to be picked up continually and is useful for
-                        testing purposes.</li>
+                        testing purposes.  If not keeping source file NiFi will need 
+                        at least write permissions to the directory it is pulling from
+                        otherwise it will ignore the file.</li>
                     <li>Default value: false</li>
                     <li>Supports expression language: false</li>
                 </ul></li>