public boolean deleteAssetIfExists(final JGitPathImpl path, final DeleteOption... options) { final PathInfo result = path.getFileSystem().getGit().getPathInfo(path.getRefTree(), path.getPath()); if (result.getPathType().equals(PathType.DIRECTORY)) { if (deleteNonEmptyDirectory(options)) { deleteResource(path, options); return true; } final List<PathInfo> content = path.getFileSystem().getGit().listPathContent(path.getRefTree(), path.getPath()); if (content.size() == 1 && content.get(0).getPath().equals(path.getPath().substring(1) + "/.gitkeep")) { delete(path.resolve(".gitkeep")); return true; } throw new DirectoryNotEmptyException(path.toString()); } if (result.getPathType().equals(NOT_FOUND)) { return false; } deleteResource(path, options); return true; }
public void deleteAsset(final JGitPathImpl path, final DeleteOption... options) { final PathInfo result = path.getFileSystem().getGit().getPathInfo(path.getRefTree(), path.getPath()); if (result.getPathType().equals(PathType.DIRECTORY)) { if (deleteNonEmptyDirectory(options)) { deleteResource(path, options); return; } final List<PathInfo> content = path.getFileSystem().getGit().listPathContent(path.getRefTree(), path.getPath()); if (content.size() == 1 && content.get(0).getPath().equals(path.getPath().substring(1) + "/.gitkeep")) { delete(path.resolve(".gitkeep")); deleteResource(path, options); return; } throw new DirectoryNotEmptyException(path.toString()); } if (result.getPathType().equals(NOT_FOUND)) { throw new NoSuchFileException(path.toString()); } deleteResource(path, options); }
@Test public void testCreateDirectory() { final URI newRepo = URI.create("git://xcreatedir-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); final JGitPathImpl path = (JGitPathImpl) provider.getPath(URI.create("git://master@xcreatedir-test-repo/some/path/to/")); final PathInfo result = path.getFileSystem().getGit().getPathInfo(path.getRefTree(), path.getPath()); assertThat(result.getPathType()).isEqualTo(PathType.NOT_FOUND); provider.createDirectory(path); final PathInfo resultAfter = path.getFileSystem().getGit().getPathInfo(path.getRefTree(), path.getPath()); assertThat(resultAfter.getPathType()).isEqualTo(PathType.DIRECTORY); final Path gitkeepPath = path.resolve(".gitkeep"); assertThat(provider.exists(gitkeepPath)).isEqualTo(true); try { provider.createDirectory(path); failBecauseExceptionWasNotThrown(FileAlreadyExistsException.class); } catch (FileAlreadyExistsException ignored) { } }
@Test public void testCreateDirectory() { final URI newRepo = URI.create("git://xcreatedir-test-repo"); provider.newFileSystem(newRepo, EMPTY_ENV); final JGitPathImpl path = (JGitPathImpl) provider.getPath(URI.create("git://master@xcreatedir-test-repo/some/path/to/")); final PathInfo result = path.getFileSystem().getGit().getPathInfo(path.getRefTree(), path.getPath()); assertThat(result.getPathType()).isEqualTo(PathType.NOT_FOUND); provider.createDirectory(path); final PathInfo resultAfter = path.getFileSystem().getGit().getPathInfo(path.getRefTree(), path.getPath()); assertThat(resultAfter.getPathType()).isEqualTo(PathType.DIRECTORY); final Path gitkeepPath = path.resolve(".gitkeep"); assertThat(provider.exists(gitkeepPath)).isEqualTo(true); try { provider.createDirectory(path); failBecauseExceptionWasNotThrown(FileAlreadyExistsException.class); } catch (FileAlreadyExistsException ignored) { } }