Github user alasdairhodge commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/115#discussion_r16181473
--- 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 --
`checkFileReadable()` test also performed by calling method, so arguable
not required (although I think this should be a generic utility method).
"Check-then-act" is a race condition; suggest handling both cases
identically (ideally without duplicating code).
---
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.
---