dsmiley commented on code in PR #2924: URL: https://github.com/apache/solr/pull/2924#discussion_r1919169585
########## solr/core/src/java/org/apache/solr/handler/admin/ShowFileRequestHandler.java: ########## @@ -195,54 +195,69 @@ private void showFromZooKeeper( } // Return the file indicated (or the directory listing) from the local file system. - private void showFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp) { + private void showFromFileSystem(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { Path admin = getAdminFileFromFileSystem(req, rsp, hiddenFiles); if (admin == null) { // exception already recorded return; } - // TODO SOLR-8282 move to PATH - File adminFile = admin.toFile(); + Path adminFile = admin; // Make sure the file exists, is readable and is not a hidden file - if (!adminFile.exists()) { - log.error("Can not find: {} [{}]", adminFile.getName(), adminFile.getAbsolutePath()); + if (!Files.exists(adminFile)) { + log.error("Can not find: {} [{}]", adminFile.getFileName(), adminFile.toAbsolutePath()); rsp.setException( new SolrException( ErrorCode.NOT_FOUND, - "Can not find: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]")); + "Can not find: " + + adminFile.getFileName() + + " [" + + adminFile.toAbsolutePath() + + "]")); return; } - if (!adminFile.canRead() || adminFile.isHidden()) { - log.error("Can not show: {} [{}]", adminFile.getName(), adminFile.getAbsolutePath()); + if (!Files.isReadable(adminFile) || Files.isHidden(adminFile)) { + log.error("Can not show: {} [{}]", adminFile.getFileName(), adminFile.toAbsolutePath()); rsp.setException( new SolrException( ErrorCode.NOT_FOUND, - "Can not show: " + adminFile.getName() + " [" + adminFile.getAbsolutePath() + "]")); + "Can not show: " + + adminFile.getFileName() + + " [" + + adminFile.toAbsolutePath() + + "]")); return; } // Show a directory listing - if (adminFile.isDirectory()) { + if (Files.isDirectory(adminFile)) { // it's really a directory, just go for it. - int basePath = adminFile.getAbsolutePath().length() + 1; NamedList<SimpleOrderedMap<Object>> files = new SimpleOrderedMap<>(); - for (File f : adminFile.listFiles()) { - String path = f.getAbsolutePath().substring(basePath); - path = path.replace('\\', '/'); // normalize slashes - - if (isHiddenFile(req, rsp, f.getName().replace('\\', '/'), false, hiddenFiles)) { - continue; - } - - SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<>(); - files.add(path, fileInfo); - if (f.isDirectory()) { - fileInfo.add("directory", true); - } else { - // TODO? content type - fileInfo.add("size", f.length()); - } - fileInfo.add("modified", new Date(f.lastModified())); + try (Stream<Path> directoryFiles = Files.list(adminFile)) { + directoryFiles.forEach( + (f) -> { + String path = f.getFileName().toString(); + + if (isHiddenFile(req, rsp, f.getFileName().toString(), false, hiddenFiles)) { + return; + } + + SimpleOrderedMap<Object> fileInfo = new SimpleOrderedMap<>(); + files.add(path, fileInfo); + if (Files.isDirectory(f)) { + fileInfo.add("directory", true); + } else { + // TODO? content type Review Comment: An aside: The question mark there definitely doesn't convey the urgency that Eric suggests. There just isn't a universal interpretation of TODOs across projects (sadly). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org