NIFI-2818 - Minimise fs permission required by NiFi

1 - Replace a r/w test over $NIFI_HOME/lib that is performed
            but never utilised by a RO test
            2 - Rename ensureDirectoryExistAndCanAccess to
            ensureDirectoryExistAndCanReadAndWrite and deprecate the
            former
This commit is contained in:
Andre F de Miranda 2016-09-24 22:02:04 +10:00 committed by joewitt
parent 52cde9ad13
commit f32bdf7be9
2 changed files with 22 additions and 5 deletions

View File

@ -72,14 +72,16 @@ public final class NarUnpacker {
final List<File> narFiles = new ArrayList<>(); final List<File> narFiles = new ArrayList<>();
// make sure the nar directories are there and accessible // make sure the nar directories are there and accessible
FileUtils.ensureDirectoryExistAndCanAccess(frameworkWorkingDir); FileUtils.ensureDirectoryExistAndCanReadAndWrite(frameworkWorkingDir);
FileUtils.ensureDirectoryExistAndCanAccess(extensionsWorkingDir); FileUtils.ensureDirectoryExistAndCanReadAndWrite(extensionsWorkingDir);
FileUtils.ensureDirectoryExistAndCanAccess(docsWorkingDir); FileUtils.ensureDirectoryExistAndCanReadAndWrite(docsWorkingDir);
for (Path narLibraryDir : narLibraryDirs) { for (Path narLibraryDir : narLibraryDirs) {
File narDir = narLibraryDir.toFile(); File narDir = narLibraryDir.toFile();
FileUtils.ensureDirectoryExistAndCanAccess(narDir);
// Test if the source NARs can be read
FileUtils.ensureDirectoryExistAndCanRead(narDir);
File[] dirFiles = narDir.listFiles(NAR_FILTER); File[] dirFiles = narDir.listFiles(NAR_FILTER);
if (dirFiles != null) { if (dirFiles != null) {

View File

@ -33,8 +33,14 @@ public class FileUtils {
public static final long MILLIS_BETWEEN_ATTEMPTS = 50L; public static final long MILLIS_BETWEEN_ATTEMPTS = 50L;
/* Superseded by renamed class bellow */
@Deprecated
public static void ensureDirectoryExistAndCanAccess(final File dir) throws IOException { public static void ensureDirectoryExistAndCanAccess(final File dir) throws IOException {
if (dir.exists() && !dir.isDirectory()) { ensureDirectoryExistAndCanReadAndWrite(dir);
}
public static void ensureDirectoryExistAndCanReadAndWrite(final File dir) throws IOException {
if (dir.exists() && !dir.isDirectory() ) {
throw new IOException(dir.getAbsolutePath() + " is not a directory"); throw new IOException(dir.getAbsolutePath() + " is not a directory");
} else if (!dir.exists()) { } else if (!dir.exists()) {
final boolean made = dir.mkdirs(); final boolean made = dir.mkdirs();
@ -47,6 +53,15 @@ public class FileUtils {
} }
} }
public static void ensureDirectoryExistAndCanRead(final File dir) throws IOException {
if (dir.exists() && !dir.isDirectory()) {
throw new IOException(dir.getAbsolutePath() + " is not a directory");
}
if (dir.exists() && !dir.canRead()) {
throw new IOException(dir.getAbsolutePath() + " directory does not have read privilege");
}
}
/** /**
* Deletes the given file. If the given file exists but could not be deleted * Deletes the given file. If the given file exists but could not be deleted
* this will be printed as a warning to the given logger * this will be printed as a warning to the given logger