private static void collectFiles(VirtualFile d, Collection<String> names, String prefix) throws IOException { for (VirtualFile child : d.list()) { if (child.isFile()) { names.add(prefix + child.getName()); } else if (child.isDirectory()) { collectFiles(child, names, prefix + child.getName() + "/"); } } } }
/** * Builds the path list and href recursively top-down. */ private static void buildPathList(VirtualFile baseDir, VirtualFile filePath, List<Path> pathList, StringBuilder href) throws IOException { VirtualFile parent = filePath.getParent(); if (!baseDir.equals(parent)) { buildPathList(baseDir, parent, pathList, href); } href.append(Util.rawEncode(filePath.getName())); if (filePath.isDirectory()) { href.append("/"); } Path path = new Path(href.toString(), filePath.getName(), filePath.isDirectory(), filePath.length(), filePath.canRead(), filePath.lastModified()); pathList.add(path); }
Path p = new Path(Util.rawEncode(f.getName()), f.getName(), f.isDirectory(), f.length(), f.canRead(), f.lastModified()); if(!f.isDirectory()) { r.add(Collections.singletonList(p)); String relPath = Util.rawEncode(f.getName()); while(true) { String name = vf.getName(); if (!name.startsWith(".") && !name.equals("CVS") && !name.equals(".svn")) { sub.add(vf); break; f = sub.get(0); relPath += '/'+Util.rawEncode(f.getName()); l.add(new Path(relPath,f.getName(),true, f.length(), f.canRead(), f.lastModified()));
String child = sub.getName(); String childPath = path + child; String childHref = pathHref + Util.rawEncode(child);
if (glob.length() == 0) { relativePath = dir.getName() + '/' + n; } else { relativePath = n;
try (OutputStream os = rsp.getOutputStream()) { for (VirtualFile kid : baseFile.list()) { os.write(kid.getName().getBytes("UTF-8")); if (kid.isDirectory()) { os.write('/'); if (view) { rsp.setHeader("Content-Disposition", "inline; filename=" + baseFile.getName()); rsp.serveFile(req, in, lastModified, -1, length, baseFile.getName() );
Path p = new Path(Util.rawEncode(f.getName()), f.getName(), f.isDirectory(), f.length(), f.canRead()); if(!f.isDirectory()) { r.add(Collections.singletonList(p)); String relPath = Util.rawEncode(f.getName()); while(true) { String name = vf.getName(); if (!name.startsWith(".") && !name.equals("CVS") && !name.equals(".svn")) { sub.add(vf); break; f = sub.get(0); relPath += '/'+Util.rawEncode(f.getName()); l.add(new Path(relPath,f.getName(),true,0, f.canRead()));
private String fullName(VirtualFile file, VirtualFile root) throws IOException { StringBuilder name = new StringBuilder(file.getName()); VirtualFile parent = file.getParent(); while (parent != null && parent.isDirectory() && !parent.equals(root)) { if(!StringUtils.isEmpty(parent.getName())) { name.insert(0, parent.getName() + "/"); } parent = parent.getParent(); } return name.toString(); }
/** * Builds the path list and href recursively top-down. */ private static void buildPathList(VirtualFile baseDir, VirtualFile filePath, List<Path> pathList, StringBuilder href) throws IOException { VirtualFile parent = filePath.getParent(); if (!baseDir.equals(parent)) { buildPathList(baseDir, parent, pathList, href); } href.append(Util.rawEncode(filePath.getName())); if (filePath.isDirectory()) { href.append("/"); } Path path = new Path(href.toString(), filePath.getName(), filePath.isDirectory(), filePath.length(), filePath.canRead()); pathList.add(path); }
private static void zip(OutputStream outputStream, VirtualFile dir, String glob) throws IOException { try (ZipOutputStream zos = new ZipOutputStream(outputStream)) { zos.setEncoding(System.getProperty("file.encoding")); // TODO JENKINS-20663 make this overridable via query parameter for (String n : dir.list(glob.length() == 0 ? "**" : glob)) { String relativePath; if (glob.length() == 0) { // JENKINS-19947: traditional behavior is to prepend the directory name relativePath = dir.getName() + '/' + n; } else { relativePath = n; } // In ZIP archives "All slashes MUST be forward slashes" (http://pkware.com/documents/casestudies/APPNOTE.TXT) // TODO On Linux file names can contain backslashes which should not treated as file separators. // Unfortunately, only the file separator char of the master is known (File.separatorChar) // but not the file separator char of the (maybe remote) "dir". ZipEntry e = new ZipEntry(relativePath.replace('\\', '/')); VirtualFile f = dir.child(n); e.setTime(f.lastModified()); zos.putNextEntry(e); try (InputStream in = f.open()) { IOUtils.copy(in, zos); } zos.closeEntry(); } } }
String child = sub.getName(); String childPath = path + child; String childHref = pathHref + Util.rawEncode(child);
try (OutputStream os = rsp.getOutputStream()) { for (VirtualFile kid : baseFile.list()) { os.write(kid.getName().getBytes("UTF-8")); if (kid.isDirectory()) { os.write('/'); if (view) { rsp.setHeader("Content-Disposition", "inline; filename=" + baseFile.getName()); rsp.serveFile(req, in, lastModified, -1, length, baseFile.getName() );