@@ -0,0 +1,1779 @@
+package com.peterphi.std.guice.metrics.health;%0A%0Aimport org.apache.commons.io.FileUtils;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.util.UUID;%0A%0A/**%0A * A health determine if a given folder can be read/written%0A */%0Apublic abstract class FolderAccessibleCheck extends AbstractHealthCheck%0A%7B%0A%0A%0A%09@Override%0A%09protected Result check() throws Exception%0A%09%7B%0A%09%09String path = getPath();%0A%0A%09%09%7B%0A%09%09%09File f = new File(path);%0A%0A%09%09%09if (!f.canRead())%0A%09%09%09%7B%0A%09%09%09%09return Result.unhealthy(%22Cannot read from %22 + path);%0A%09%09%09%7D%0A%09%09%7D%0A%0A%09%09%7B%0A%0A%09%09%09File f = new File(path);%0A%0A%09%09%09if (doWriteCheck())%0A%09%09%09%7B%0A%09%09%09%09if (!f.canWrite())%0A%09%09%09%09%7B%0A%09%09%09%09%09return Result.unhealthy(%22Cannot write to %22 + path);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%0A%09%09%09if (doWriteTest())%0A%09%09%09%7B%0A%0A%09%09%09%09UUID uuid = UUID.randomUUID();%0A%0A%09%09%09%09File testfile = new File(path, uuid.toString() + %22.tmp%22);%0A%0A%09%09%09%09try%0A%09%09%09%09%7B%0A%09%09%09%09%09try%0A%09%09%09%09%09%7B%0A%09%09%09%09%09%09FileUtils.write(testfile, uuid.toString());%0A%0A%09%09%09%09%09%09String read = FileUtils.readFileToString(testfile);%0A%0A%09%09%09%09%09%09if (!read.equals(uuid.toString()))%0A%09%09%09%09%09%09%7B%0A%09%09%09%09%09%09%09return Result.unhealthy(%22Cannot read/write %22 + path);%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D%0A%09%09%09%09%09finally%0A%09%09%09%09%09%7B%0A%09%09%09%09%09%09testfile.delete();%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%09catch (IOException e)%0A%09%09%09%09%7B%0A%09%09%09%09%09return Result.unhealthy(%22Error reading/writing from %22 + path + %22 %22 + e.getMessage());%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%0A%0A%09%09return Result.healthy();%0A%09%7D%0A%0A%0A%09/**%0A%09 * The path to the folder concerned%0A%09 * @return%0A%09 */%0A%09protected abstract String getPath();%0A%0A%09/**%0A%09 * If true, a permissions based check check will be performed to see if this application can write to the folder%0A%09 * @return%0A%09 */%0A%09protected abstract boolean doWriteCheck();%0A%0A%09/**%0A%09 * If true, the ability to write to the folder will be check by actually performing a file write (the written file is then deleted)%0A%09 * @return%0A%09 */%0A%09protected abstract boolean doWriteTest();%0A%0A%7D%0A

add folder accessible check to stdlib