public FileBlobStore(final Platform platform) { Optional<URI> repoPath = new ResolveGeogigURI(platform, null).call(); Preconditions.checkState(repoPath.isPresent(), "Not inside a geogig directory"); URI uri = repoPath.get(); Preconditions.checkState("file".equals(uri.getScheme()), "Repository URL is not file system based: %s", uri); File repoLocation = new File(uri); this.repositoryDirectory = repoLocation; }
@Override public boolean repoExists(URI repoURI) { File directory = toFile(repoURI); Optional<URI> lookup = ResolveGeogigURI.lookup(directory); return lookup.isPresent(); }
public static Optional<URI> lookup(final File directory) { try { return Optional.fromNullable(lookupGeogigDirectory(directory)); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void delete(String repoName) { Preconditions.checkState(repo != null, "No repository to delete."); Optional<URI> repoUri = repo.command(ResolveGeogigURI.class).call(); Preconditions.checkState(repoUri.isPresent(), "No repository to delete."); repo.close(); try { GeoGIG.delete(repoUri.get()); this.repo = null; } catch (Exception e) { Throwables.propagate(e); } }
@Override public void delete(String repoName) { Optional<Repository> geogig = getGeogig(repoName); Preconditions.checkState(geogig.isPresent(), "No repository to delete."); Repository ggig = geogig.get(); Optional<URI> repoUri = ggig.command(ResolveGeogigURI.class).call(); Preconditions.checkState(repoUri.isPresent(), "No repository to delete."); ggig.close(); try { GeoGIG.delete(repoUri.get()); this.repositories.invalidate(repoName); } catch (Exception e) { Throwables.propagate(e); } }
File getGeoGigDirectory() { final Optional<URI> repoUrl = new ResolveGeogigURI(platform, hints).call(); if (!repoUrl.isPresent()) { throw new IllegalStateException("Can't find geogig repository home"); } URI uri = repoUrl.get(); Preconditions.checkState("file".equals(uri.getScheme()), "Can't create BDB JE Environment on a non file repository URI: %s", uri); return new File(uri); }
private void resolveGeogigDir(Console console, GeoGIG geogig) throws IOException { URI repoUrl = geogig.command(ResolveGeogigURI.class).call().orNull(); if (null == repoUrl) { File currDir = geogig.getPlatform().pwd(); console.println("Error: not a geogig dir '" + currDir.getCanonicalFile().getAbsolutePath() + "'"); } else if ("file".equals(repoUrl.getScheme())) { console.println(new File(repoUrl).getCanonicalFile().getAbsolutePath()); } else { console.println(repoUrl.toString()); } }
@Override public boolean repoExists(URI repoURI) { File directory = toFile(repoURI); Optional<URI> lookup = ResolveGeogigURI.lookup(directory); return lookup.isPresent(); }
public static Optional<URI> lookup(final File directory) { try { return Optional.fromNullable(lookupGeogigDirectory(directory)); } catch (IOException e) { throw Throwables.propagate(e); } }
public FileBlobStore(final Platform platform) { Optional<URI> repoPath = new ResolveGeogigURI(platform, null).call(); Preconditions.checkState(repoPath.isPresent(), "Not inside a geogig directory"); URI uri = repoPath.get(); Preconditions.checkState("file".equals(uri.getScheme()), "Repository URL is not file system based: %s", uri); File repoLocation = new File(uri); this.repositoryDirectory = repoLocation; }
@Override protected Boolean _call() { final Optional<URI> repoUrl = command(ResolveGeogigURI.class).call(); Boolean hasConflicts = Boolean.FALSE; if (repoUrl.isPresent()) { boolean conflicts = conflictsDatabase().hasConflicts(null); hasConflicts = Boolean.valueOf(conflicts); } return hasConflicts; } }
@Test public void testReinitializeExistingRepoFromInsideASubdirectory() throws Exception { testCreateNewRepo(); File subDir = new File(new File(workingDir, "subdir1"), "subdir2"); assertTrue(subDir.mkdirs()); when(platform.pwd()).thenReturn(subDir); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); assertNotNull(init.call()); verify(platform, atLeastOnce()).pwd(); } }
/** * @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()); }
@Inject public RocksdbGraphDatabase(Platform platform, Hints hints) { this.readOnly = hints == null ? false : hints.getBoolean(Hints.OBJECTS_READ_ONLY); Optional<URI> uri = new ResolveGeogigURI(platform, hints).call(); Preconditions.checkArgument(uri.isPresent(), "not in a geogig directory"); Preconditions.checkArgument("file".equals(uri.get().getScheme()), "Repository URI is not file://"); File basedir = new File(uri.get()); this.dbdir = new File(basedir, "graph.rocksdb"); }
private void resolveGeogigDir(Console console, GeoGIG geogig) throws IOException { URI repoUrl = geogig.command(ResolveGeogigURI.class).call().orNull(); if (null == repoUrl) { File currDir = geogig.getPlatform().pwd(); console.println("Error: not a geogig dir '" + currDir.getCanonicalFile().getAbsolutePath() + "'"); } else if ("file".equals(repoUrl.getScheme())) { console.println(new File(repoUrl).getCanonicalFile().getAbsolutePath()); } else { console.println(repoUrl.toString()); } }
@Test public void testReinitializeExistingRepoFromInsideASubdirectory() throws Exception { testCreateNewRepo(); File subDir = new File(new File(workingDir, "subdir1"), "subdir2"); assertTrue(subDir.mkdirs()); when(platform.pwd()).thenReturn(subDir); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); assertNotNull(init.call()); verify(platform, atLeastOnce()).pwd(); } }
/** * @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()); }
public RocksdbObjectStore(Platform platform, @Nullable Hints hints, String databaseName) { checkNotNull(platform); this.platform = platform; this.hints = hints; Optional<URI> repoUriOpt = new ResolveGeogigURI(platform, hints).call(); checkArgument(repoUriOpt.isPresent(), "couldn't resolve geogig directory"); URI uri = repoUriOpt.get(); checkArgument("file".equals(uri.getScheme())); this.path = new File(new File(uri), databaseName).getAbsolutePath(); this.readOnly = hints == null ? false : hints.getBoolean(Hints.OBJECTS_READ_ONLY); }