Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/115#discussion_r16231122
--- Diff:
usage/launcher/src/main/java/brooklyn/launcher/BrooklynLauncher.java ---
@@ -485,6 +498,37 @@ public BrooklynLauncher start() {
return this;
}
+ private void checkFileReadable(String file) {
+ File f = new File(Os.tidyPath(file));
+ if (!f.exists()) {
+ throw new FatalRuntimeException("File "+file+" does not
exist");
+ }
+ if (!f.isFile()) {
+ throw new FatalRuntimeException(file+" is not a file");
+ }
+ if (!f.canRead()) {
+ throw new FatalRuntimeException(file+" is not readable");
+ }
+ }
+
+ private void checkFilePermissionsX00(String file) {
+ File f = new File(Os.tidyPath(file));
+ if (f.exists() && f.isFile() && f.canRead()) {
+ try {
+ Maybe<String> permission = FileUtil.getFilePermissions(f);
+ if (permission.isAbsent()) {
+ LOG.debug("Could not determine permissions of global
brooklyn properties file; assuming ok: "+f);
+ } else {
+ if (!permission.get().substring(4).equals("------")) {
+ throw new FatalRuntimeException("Invalid
permissions for file "+file+"; expected 600 but was "+permission.get());
+ }
+ }
+ } catch (FileNotFoundException e) {
+ throw Exceptions.propagate(e); // should not happen; did
f.exists() above
+ }
+ }
+ }
+
--- End diff --
Tricky to cleanly always do the check before acting, without duplicating
the checks (even if the code is reused by extracting to a shared method). I'm
inclined to rely on `builder.globalPropertiesFile` not breaking if you give it
a file that does not exist. It won't give a particularly nice warning (it might
even ignore silently!). If the file is deleted between our first check and the
builder doing its stuff then so be it.
Removing duplicate checks from `checkFilePermissionsX00`
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---