/** * ValidateWritable FileSystem * * @param path the path to check * @param checkDirectory if true, then ensure that the file specified by {@code path} is not a * directory * @throws StandardException */ public static void validateWritable(String path, boolean checkDirectory) throws StandardException { // check that the badLogDirectory exists and is writable if (path == null) return; DistributedFileSystem fsLayer = getFileSystem(path); FileInfo info; try { info = fsLayer.getInfo(path); } catch (IOException e) { throw Exceptions.parseException(e); } if (checkDirectory && !info.isDirectory()) { throw ErrorState.DATA_FILE_NOT_FOUND.newException(path); } if (!info.isWritable()) { throw ErrorState.LANG_NO_WRITE_PERMISSION.newException(info.getUser(), info.getGroup(), path); } }
/** * Check that the file given by the string path (or directory, if flagged) exists and is readable. * * @param file the absolute path to the file * @param checkDirectory check as a directory if this flag set * @throws StandardException */ public static void validateReadable(String file, boolean checkDirectory) throws StandardException { if (file == null) return; DistributedFileSystem fsLayer = getFileSystem(file); FileInfo info; try { info = fsLayer.getInfo(file); } catch (IOException e) { throw Exceptions.parseException(e); } if (!info.exists() || (checkDirectory && info.isDirectory())) throw ErrorState.LANG_FILE_DOES_NOT_EXIST.newException(file); if (!info.isReadable()) { throw ErrorState.LANG_NO_READ_PERMISSION.newException(info.getUser(), info.getGroup(), file); } }