@Override public VirtualFile[] list() throws IOException { if (isIllegalSymlink()) { return new VirtualFile[0]; } File[] kids = f.listFiles(); if (kids == null) { return new VirtualFile[0]; } VirtualFile[] vfs = new VirtualFile[kids.length]; for (int i = 0; i < kids.length; i++) { vfs[i] = new FileVF(kids[i], root); } return vfs; } @Override
/** * TODO un-restrict it in a weekly after the patch */ @Override @Restricted(NoExternalUse.class) public boolean isDescendant(String potentialChildRelativePath) throws IOException { if (new File(potentialChildRelativePath).isAbsolute()) { throw new IllegalArgumentException("Only a relative path is supported, the given path is absolute: " + potentialChildRelativePath); } FilePath root = new FilePath(this.root); String relativePath = computeRelativePathToRoot(); try { return root.isDescendant(relativePath + potentialChildRelativePath); } catch (InterruptedException e) { return false; } }
@Override public VirtualFile[] list() throws IOException { if (isIllegalSymlink()) { return new VirtualFile[0]; } File[] kids = f.listFiles(); if (kids == null) { return new VirtualFile[0]; } VirtualFile[] vfs = new VirtualFile[kids.length]; for (int i = 0; i < kids.length; i++) { vfs[i] = new FileVF(kids[i], root); } return vfs; } @Override public String[] list(String glob) throws IOException {
@Override public VirtualFile getParent() { return new FileVF(f.getParentFile(), root); } @Override public boolean isDirectory() throws IOException {
@Override public InputStream open() throws IOException { if (isIllegalSymlink()) { throw new FileNotFoundException(f.getPath()); } try { return Files.newInputStream(f.toPath()); } catch (InvalidPathException e) { throw new IOException(e); } } private boolean isIllegalSymlink() { // TODO JENKINS-26838
@Override public boolean canRead() throws IOException { if (isIllegalSymlink()) { return false; } return f.canRead(); } @Override public InputStream open() throws IOException {
@Override public boolean exists() throws IOException { if (isIllegalSymlink()) { return false; } return f.exists(); } @Override public VirtualFile[] list() throws IOException {
@Override public boolean isDirectory() throws IOException { if (isIllegalSymlink()) { return false; } return f.isDirectory(); } @Override public boolean isFile() throws IOException {
@Override public String[] list(String glob) throws IOException { if (isIllegalSymlink()) { return new String[0]; } return new Scanner(glob).invoke(f, null); } @Override public VirtualFile child(String name) {
@Override public boolean isFile() throws IOException { if (isIllegalSymlink()) { return false; } return f.isFile(); } @Override public boolean exists() throws IOException {
@Override public long lastModified() throws IOException { if (isIllegalSymlink()) { return 0; } return f.lastModified(); } @Override public boolean canRead() throws IOException {
/** * Creates a virtual file wrapper for a local file. * @param f a disk file (need not exist) * @return a wrapper */ public static VirtualFile forFile(final File f) { return new FileVF(f, f); } private static final class FileVF extends VirtualFile {
@Override public VirtualFile child(String name) { return new FileVF(new File(f, name), root); } @Override public long length() throws IOException {
@Override public long length() throws IOException { if (isIllegalSymlink()) { return 0; } return f.length(); } @Override public long lastModified() throws IOException {
@Override public boolean canRead() throws IOException { if (isIllegalSymlink()) { return false; } return f.canRead(); } @Override public InputStream open() throws IOException {
@Override public boolean exists() throws IOException { if (isIllegalSymlink()) { return false; } return f.exists(); } @Override public String readLink() throws IOException {
@Override public long lastModified() throws IOException { if (isIllegalSymlink()) { return 0; } return f.lastModified(); } @Override public boolean canRead() throws IOException {
@Override public int mode() throws IOException { if (isIllegalSymlink()) { return -1; } return IOUtils.mode(f); } @Override public long lastModified() throws IOException {
@Override public Collection<String> list(String includes, String excludes, boolean useDefaultExcludes) throws IOException { if (isIllegalSymlink()) { return Collections.emptySet(); } return new Scanner(includes, excludes, useDefaultExcludes).invoke(f, null); } @Override public VirtualFile child(String name) {
@Override public String readLink() throws IOException { if (isIllegalSymlink()) { return null; // best to just ignore link -> ../whatever } return Util.resolveSymlink(f); } @Override public VirtualFile[] list() throws IOException {