@Override public BasicFileAttributes readAttributes() throws IOException { if (attrs == null) { attrs = buildAttrs(path.getFileSystem(), path.getRefTree(), path.getPath()); } return attrs; }
public static JGitPathImpl createRoot(final JGitFileSystem fs, final String path, final String host, final boolean isRealPath) { return new JGitPathImpl(fs, setupPath(path), setupHost(host), null, true, isRealPath, true); }
private void createBranch(final JGitPathImpl source, final JGitPathImpl target) { JGitUtil.createBranch(source.getFileSystem().gitRepo(), source.getRefTree(), target.getRefTree()); }
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); }
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())); } }
private boolean hasSameFileSystem(final JGitPathImpl source, final JGitPathImpl target) { return source.getFileSystem().equals(target.getFileSystem()); }
final PathInfo pathResult = gPath.getFileSystem().getGit().getPathInfo(gPath.getRefTree(), gPath.getPath()); if (pathResult.getPathType().equals(NOT_FOUND)) { throw new NoSuchFileException(path.toString()); final V resultView = gPath.getAttrView(type); gPath.addAttrView(newView); return newView; } else if (type == HiddenAttributeView.class || type == JGitHiddenAttributeView.class) { final V newView = (V) new JGitHiddenAttributeView(gPath); gPath.addAttrView(newView); return newView; } else if (type == VersionAttributeView.class || type == JGitVersionAttributeView.class) { final V newView = (V) new JGitVersionAttributeView(gPath); gPath.addAttrView(newView); return newView;
@Override public Path getPath(final String first, final String... more) throws InvalidPathException { checkClose(); checkNotEmpty("first", first); if (more == null || more.length == 0) { return JGitPathImpl.create(this, first, JGitPathImpl.DEFAULT_REF_TREE + "@" + name, false); } final StringBuilder sb = new StringBuilder(); for (final String segment : more) { if (segment.length() > 0) { if (sb.length() > 0) { sb.append(getSeparator()); } sb.append(segment); } } return JGitPathImpl.create(this, sb.toString(), first + "@" + name, false); }
public void deleteBranch(final JGitPathImpl path) { final Ref branch = path.getFileSystem().getGit().getRef(path.getRefTree()); if (branch == null) { throw new NoSuchFileException(path.toString()); } try { path.getFileSystem().lock(); path.getFileSystem().getGit().deleteRef(branch); } finally { path.getFileSystem().unlock(); } }
private void moveBranch(final JGitPathImpl source, final JGitPathImpl target, final CopyOption... options) { checkCondition("source and target should have same file system", hasSameFileSystem(source, target)); if (!exists(source)) { throw new NoSuchFileException(target.toString()); } boolean targetExists = existsBranch(target); if (targetExists && !contains(options, StandardCopyOption.REPLACE_EXISTING)) { throw new FileAlreadyExistsException(target.toString()); } if (!targetExists) { createBranch(source, target); deleteBranch(source); } else { commit(target, buildCommitInfo("reverting from {" + source.getPath() + "}", Arrays.asList(options)), new RevertCommitContent(source.getRefTree())); } }
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)))); }
@Override public boolean isHidden(final Path path) throws IllegalArgumentException, IOException, SecurityException { checkNotNull("path", path); final JGitPathImpl gPath = toPathImpl(path); if (gPath.getFileName() == null) { return false; } return toPathImpl(path.getFileName()).toString(false).startsWith("."); }
public static JGitPathImpl createFSDirect(final JGitFileSystem fs) { return new JGitPathImpl(fs, null, null, null, true, true, true); }
@Override public String getSegmentId() { return getRefTree(); } }
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; }
private Map<JGitPathImpl, JGitPathImpl> mapDirectoryContent(final JGitPathImpl source, final JGitPathImpl target, final CopyOption... options) { final Map<JGitPathImpl, JGitPathImpl> fromTo = new HashMap<>(); for (final Path path : newDirectoryStream(source, null)) { final JGitPathImpl gPath = toPathImpl(path); final PathInfo pathResult = gPath.getFileSystem().getGit().getPathInfo(gPath.getRefTree(), gPath.getPath()); if (pathResult.getPathType() == DIRECTORY) { fromTo.putAll(mapDirectoryContent(gPath, composePath(target, (JGitPathImpl) gPath.getFileName()))); } else { final JGitPathImpl gTarget = composePath(target, (JGitPathImpl) gPath.getFileName()); fromTo.put(gPath, gTarget); } } return fromTo; }
private void merge(final JGitPathImpl source, final JGitPathImpl target) { try { target.getFileSystem().lock(); source.getFileSystem().getGit().merge(source.getRefTree(), target.getRefTree()); } finally { target.getFileSystem().unlock(); } }
private boolean hasSameFileSystem(final JGitPathImpl source, final JGitPathImpl target) { return source.getFileSystem().equals(target); }
@Override public Path getPath(final String first, final String... more) throws InvalidPathException { checkClosed(); if (first == null || first.trim().isEmpty()) { return new JGitFSPath(this); } if (more == null || more.length == 0) { return JGitPathImpl.create(this, first, JGitPathImpl.DEFAULT_REF_TREE + "@" + name, false); } final StringBuilder sb = new StringBuilder(); for (final String segment : more) { if (segment.length() > 0) { if (sb.length() > 0) { sb.append(getSeparator()); } sb.append(segment); } } return JGitPathImpl.create(this, sb.toString(), first + "@" + name, false); }