public static Optional<URI> lookup(final File directory) { try { return Optional.fromNullable(lookupGeogigDirectory(directory)); } catch (IOException e) { throw new RuntimeException(e); } }
public static Optional<URI> lookup(final File directory) { try { return Optional.fromNullable(lookupGeogigDirectory(directory)); } catch (IOException e) { throw Throwables.propagate(e); } }
/** * @param file the directory to search * @return the location of the {@code .geogig} repository environment directory or {@code null} * if not inside a working directory */ private static URI lookupGeogigDirectory(@Nullable File file) throws IOException { if (file == null || !file.exists()) { return null; } if (file.isDirectory()) { if (file.getName().equals(".geogig")) { return file.toURI(); } File[] contents = file.listFiles(); Preconditions.checkNotNull(contents, "Either '%s' is not a directory or an I/O error ocurred listing its contents", file.getAbsolutePath()); for (File dir : contents) { if (dir.isDirectory() && dir.getName().equals(".geogig")) { return lookupGeogigDirectory(dir); } } } return lookupGeogigDirectory(file.getParentFile()); }
/** * @param file the directory to search * @return the location of the {@code .geogig} repository environment directory or {@code null} * if not inside a working directory */ private static URI lookupGeogigDirectory(@Nullable File file) throws IOException { if (file == null || !file.exists()) { return null; } if (file.isDirectory()) { if (file.getName().equals(".geogig")) { return file.toURI(); } File[] contents = file.listFiles(); Preconditions.checkNotNull(contents, "Either '%s' is not a directory or an I/O error ocurred listing its contents", file.getAbsolutePath()); for (File dir : contents) { if (dir.isDirectory() && dir.getName().equals(".geogig")) { return lookupGeogigDirectory(dir); } } } return lookupGeogigDirectory(file.getParentFile()); }