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.
This commit is contained in:
Oleg Zhurakousky 2015-10-29 16:31:17 -04:00
parent c4f0cb1c6c
commit 5c4042bd7c
2 changed files with 24 additions and 0 deletions

View File

@ -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()) {

View File

@ -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 {