From 5c4042bd7c39dd92b1fba665c7b03c670346be8f Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Thu, 29 Oct 2015 16:31:17 -0400 Subject: [PATCH] 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. --- .../repository/FileSystemRepository.java | 6 ++++++ .../repository/TestFileSystemRepository.java | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) 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 72a50ecaea..2ce09470c7 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() { + + 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()) { 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 88f572bc6e..95e1f40daf 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 {