private void copyFiles(final JGitPathImpl source, final JGitPathImpl target, final Map<JGitPathImpl, JGitPathImpl> sourceDest, final CopyOption... options) { final Map<String, String> result = new HashMap<>(sourceDest.size()); for (final Map.Entry<JGitPathImpl, JGitPathImpl> sourceDestEntry : sourceDest.entrySet()) { result.put(PathUtil.normalize(sourceDestEntry.getKey().getPath()), PathUtil.normalize(sourceDestEntry.getValue().getPath())); } commit(source, buildCommitInfo("copy from {" + source.getPath() + "} to {" + target.getPath() + "}", Arrays.asList(options)), new CopyCommitContent(result)); }
private void deleteResource(final JGitPathImpl path, final DeleteOption... options) { delete(path, buildCommitInfo("delete {" + path.getPath() + "}", Arrays.asList(options))); }
@Override public BasicFileAttributes readAttributes() throws IOException { if (attrs == null) { attrs = buildAttrs(path.getFileSystem(), path.getRefTree(), path.getPath()); } return attrs; }
@Override public HiddenAttributes readAttributes() throws IOException { if (attrs == null) { attrs = buildAttrs(path.getFileSystem(), path.getRefTree(), path.getPath()); } return attrs; }
@Override public VersionAttributes readAttributes() throws IOException { if (attrs == null) { attrs = buildAttrs(path.getFileSystem(), path.getRefTree(), path.getPath()); } return attrs; }
private JGitPathImpl composePath(final JGitPathImpl directory, final JGitPathImpl fileName) { if (directory.getPath().endsWith("/")) { return toPathImpl(getPath(URI.create(directory.toUri().toString() + fileName.toString(false)))); } return toPathImpl(getPath(URI.create(directory.toUri().toString() + "/" + fileName.toString(false)))); }
private JGitPathImpl composePath(final JGitPathImpl directory, final JGitPathImpl fileName, final CopyOption... options) { if (directory.getPath().endsWith("/")) { return toPathImpl(getPath(URI.create(directory.toUri().toString() + uriEncode(fileName.toString(false))))); } return toPathImpl(getPath(URI.create(directory.toUri().toString() + "/" + uriEncode(fileName.toString(false))))); }
@Override protected BasicFileAttributes newAttrs() { return JGitUtil.buildBasicFileAttributes(this.getFileSystem().gitRepo(), this.getRefTree(), this.getPath()); }
public boolean deleteAssetIfExists(final JGitPathImpl path) { final Pair<PathType, ObjectId> result = checkPath(path.getFileSystem().gitRepo(), path.getRefTree(), path.getPath()); if (result.getK1().equals(PathType.DIRECTORY)) { throw new DirectoryNotEmptyException(path.toString()); } if (result.getK1().equals(NOT_FOUND)) { return false; } JGitUtil.delete(path.getFileSystem().gitRepo(), path.getRefTree(), path.getPath(), null, null, "delete {" + path.getPath() + "}", null, null); return true; }
public void deleteAsset(final JGitPathImpl path) { final Pair<PathType, ObjectId> result = checkPath(path.getFileSystem().gitRepo(), path.getRefTree(), path.getPath()); if (result.getK1().equals(PathType.DIRECTORY)) { throw new DirectoryNotEmptyException(path.toString()); } if (result.getK1().equals(NOT_FOUND)) { throw new NoSuchFileException(path.toString()); } JGitUtil.delete(path.getFileSystem().gitRepo(), path.getRefTree(), path.getPath(), null, null, "delete {" + path.getPath() + "}", null, null); }
@Override public InputStream newInputStream(final Path path, final OpenOption... options) throws IllegalArgumentException, UnsupportedOperationException, IOException, SecurityException { checkNotNull("path", path); final JGitPathImpl gPath = toPathImpl(path); return gPath.getFileSystem().getGit().blobAsInputStream(gPath.getRefTree(), gPath.getPath()); }
@Override public InputStream newInputStream(final Path path, final OpenOption... options) throws IllegalArgumentException, UnsupportedOperationException, NoSuchFileException, IOException, SecurityException { checkNotNull("path", path); final JGitPathImpl gPath = toPathImpl(path); return resolveInputStream(gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath()); }
@Override public void checkAccess(final Path path, final AccessMode... modes) throws UnsupportedOperationException, NoSuchFileException, AccessDeniedException, IOException, SecurityException { checkNotNull("path", path); final JGitPathImpl gPath = toPathImpl(path); final PathInfo result = gPath.getFileSystem().getGit().getPathInfo(gPath.getRefTree(), gPath.getPath()); if (result.getPathType().equals(NOT_FOUND)) { throw new NoSuchFileException(path.toString()); } }
@Override public void checkAccess(final Path path, final AccessMode... modes) throws UnsupportedOperationException, NoSuchFileException, AccessDeniedException, IOException, SecurityException { checkNotNull("path", path); final JGitPathImpl gPath = toPathImpl(path); final Pair<PathType, ObjectId> result = checkPath(gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath()); if (result.getK1().equals(NOT_FOUND)) { throw new NoSuchFileException(path.toString()); } }
@Override public boolean isSameFile(final Path pathA, final Path pathB) throws IOException, SecurityException { checkNotNull("pathA", pathA); checkNotNull("pathB", pathB); final JGitPathImpl gPathA = toPathImpl(pathA); final JGitPathImpl gPathB = toPathImpl(pathB); final Pair<PathType, ObjectId> resultA = checkPath(gPathA.getFileSystem().gitRepo(), gPathA.getRefTree(), gPathA.getPath()); final Pair<PathType, ObjectId> resultB = checkPath(gPathB.getFileSystem().gitRepo(), gPathB.getRefTree(), gPathB.getPath()); if (resultA.getK1() == PathType.FILE && resultA.getK2().equals(resultB.getK2())) { return true; } return pathA.equals(pathB); }
private void copyDirectory(final JGitPathImpl source, final JGitPathImpl target) { final List<JGitPathImpl> directories = new ArrayList<JGitPathImpl>(); for (final Path path : newDirectoryStream(source, null)) { final JGitPathImpl gPath = toPathImpl(path); final Pair<PathType, ObjectId> pathResult = checkPath(gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath()); if (pathResult.getK1() == DIRECTORY) { directories.add(gPath); continue; } final JGitPathImpl gTarget = composePath(target, (JGitPathImpl) gPath.getFileName()); copyFile(gPath, gTarget); } for (final JGitPathImpl directory : directories) { createDirectory(composePath(target, (JGitPathImpl) directory.getFileName())); } }
@Override public <A extends BasicFileAttributes> A readAttributes(final Path path, final Class<A> type, final LinkOption... options) throws NoSuchFileException, UnsupportedOperationException, IOException, SecurityException { checkNotNull("path", path); checkNotNull("type", type); final JGitPathImpl gPath = toPathImpl(path); final Pair<PathType, ObjectId> pathResult = checkPath(gPath.getFileSystem().gitRepo(), gPath.getRefTree(), gPath.getPath()); if (pathResult.getK1().equals(NOT_FOUND)) { throw new NoSuchFileException(path.toString()); } if (type == BasicFileAttributes.class || type == JGitFileAttributes.class) { final JGitFileAttributeView view = getFileAttributeView(path, JGitFileAttributeView.class, options); return (A) view.readAttributes(); } return null; }