mirror of https://github.com/apache/nifi.git
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:
parent
52cde9ad13
commit
f32bdf7be9
|
@ -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) {
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue