Github user Ethanlm commented on a diff in the pull request:

    https://github.com/apache/storm/pull/2754#discussion_r208651482
  
    --- Diff: 
storm-webapp/src/main/java/org/apache/storm/daemon/logviewer/handler/LogviewerLogPageHandler.java
 ---
    @@ -265,32 +269,26 @@ public Response daemonLogPage(String fileName, 
Integer start, Integer length, St
             String rootDir = daemonLogRoot;
             File file = new File(rootDir, fileName).getCanonicalFile();
             String path = file.getCanonicalPath();
    -        boolean isZipFile = path.endsWith(".gz");
     
             if (file.exists() && new 
File(rootDir).getCanonicalFile().equals(file.getParentFile())) {
                 // all types of files included
                 List<File> logFiles = Arrays.stream(new 
File(rootDir).listFiles())
                         .filter(File::isFile)
                         .collect(toList());
     
    -            List<String> filesStrWithoutFileParam = logFiles.stream()
    -                    .map(File::getName).filter(fName -> 
!StringUtils.equals(fileName, fName)).collect(toList());
    -
    -            List<String> reorderedFilesStr = new ArrayList<>();
    -            reorderedFilesStr.addAll(filesStrWithoutFileParam);
    +            List<String> reorderedFilesStr = logFiles.stream()
    +                .map(File::getName).filter(fName -> 
!StringUtils.equals(fileName, fName)).collect(toList());
                 reorderedFilesStr.add(fileName);
     
                 length = length != null ? Math.min(10485760, length) : 
LogviewerConstant.DEFAULT_BYTES_PER_PAGE;
    -
    -            String logString;
    -            if (isTxtFile(fileName)) {
    -                logString = escapeHtml(start != null ? pageFile(path, 
start, length) : pageFile(path, length));
    -            } else {
    -                logString = escapeHtml("This is a binary file and cannot 
display! You may download the full file.");
    +            final boolean isZipFile = path.endsWith(".gz");
    +            long fileLength = isZipFile ? ServerUtils.zipFileSize(file) : 
file.length();
    --- End diff --
    
    why not reuse `getFileLength`


---

Reply via email to