NIFI-1051 Allowed FileSystemRepository to skip un-readable entries.
The exception was caused due to basic file permissions. This fix overrides
'visitFileFailed' method of SimpleFileVisitor to log WARN message and allow
FileSystemRepository to continue.


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

Branch: refs/heads/NIFI-730
Commit: 5c4042bd7c39dd92b1fba665c7b03c670346be8f
Parents: c4f0cb1
Author: Oleg Zhurakousky <[email protected]>
Authored: Thu Oct 29 16:31:17 2015 -0400
Committer: Oleg Zhurakousky <[email protected]>
Committed: Thu Oct 29 16:31:17 2015 -0400

----------------------------------------------------------------------
 .../repository/FileSystemRepository.java          |  6 ++++++
 .../repository/TestFileSystemRepository.java      | 18 ++++++++++++++++++
 2 files changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/5c4042bd/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java
index 72a50ec..2ce0947 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/FileSystemRepository.java
@@ -309,6 +309,12 @@ public class FileSystemRepository implements 
ContentRepository {
                     // the path already exists, so scan the path to find any 
files and update maxIndex to the max of
                     // all filenames seen.
                     Files.walkFileTree(realPath, new SimpleFileVisitor<Path>() 
{
+                       
+                                               public FileVisitResult 
visitFileFailed(Path file, IOException exc) throws IOException {
+                                                       LOG.warn("Content 
repository contains un-readable file or directory '" + file.getFileName() + "'. 
Skipping. ", exc);
+                                                       return 
FileVisitResult.SKIP_SUBTREE;
+                                               }
+                                
                         @Override
                         public FileVisitResult visitFile(final Path file, 
final BasicFileAttributes attrs) throws IOException {
                             if (attrs.isDirectory()) {

http://git-wip-us.apache.org/repos/asf/nifi/blob/5c4042bd/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java
index 88f572b..95e1f40 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java
@@ -71,6 +71,24 @@ public class TestFileSystemRepository {
     public void shutdown() throws IOException {
         repository.shutdown();
     }
+    
+    @Test
+    public void testBogusFile() throws IOException {
+       repository.shutdown();
+       System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, 
"src/test/resources/nifi.properties");
+        
+        File bogus = new File(rootFile, "bogus");
+        try {
+                bogus.mkdir();
+             bogus.setReadable(false);
+        
+             repository = new FileSystemRepository();
+             repository.initialize(new StandardResourceClaimManager());
+               } finally {
+                       bogus.setReadable(true);
+                       assertTrue(bogus.delete());
+               }
+    }
 
     @Test
     public void testCreateContentClaim() throws IOException {

Reply via email to