You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2014/11/29 21:13:17 UTC

[Bug 57287] New: Sort files listed by DefaultServlet

https://issues.apache.org/bugzilla/show_bug.cgi?id=57287

            Bug ID: 57287
           Summary: Sort files listed by DefaultServlet
           Product: Tomcat 8
           Version: 8.0.15
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: knst.kolinko@gmail.com

When DefaultServlet has file listings enabled, in Tomcat 8.0.15 and 7.0.57 it
does not sort the files.

It lists them in the order provided by the underlying resources implementation.
It is a bit harder to see on Windows, where the file system lists the files in
a sorted order, but here is a reproduction recipe

1) Unpack apache-tomcat-8.0.15.zip
2) Add the following lines to webapps/ROOT/WEB-INF/web.xml

  <servlet>
      <servlet-name>default</servlet-name>
     
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
      <init-param>
          <param-name>listings</param-name>
          <param-value>true</param-value>
      </init-param>
  </servlet>
  <servlet-mapping>
      <servlet-name>default</servlet-name>
      <url-pattern>/</url-pattern>
  </servlet-mapping>

3) Delete file
webapps/ROOT/index.jsp

4) Create directory
webapps/ROOT/WEB-INF/lib/
and copy there the following file from source code
(apache-tomcat-8.0.15-src.zip):
/test/webapp-fragments/WEB-INF/lib/resources2.jar

5) Start Tomcat and access http://localhost:8080/

Actual behaviour:
Note that files "resourceB.jsp" and "resourceF.jsp" are listed at the end of
the file list, instead of any alphabetical order.

A mention of this issue by a user:
https://stackoverflow.com/questions/27166274/directory-listings-sort-order-in-tomcat-8

Expected behaviour:
List the files alphabetically.

Though my preference for the sort order is
a) sort case-insensitively
b) list the directories first

It could be improved by offering a configurable sort order:
a) by a parameter in the request
b) by a user cookie

Tomcat 7
=========
The same recipe reproduces the issue for Tomcat 7.0.57.

Workaround
===========
DefaultServlet can be configured to generate listing in XML and apply an XSLT
transformation to it. XSLT can perform sorting.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57287] Sort files listed by DefaultServlet

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=57287

--- Comment #6 from Oleg Trokhov <ot...@minsk.ximxim.com> ---
Created attachment 32249
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=32249&action=edit
sorting list

I refactor import, so checkstyle task passed. So we leave my parameter naming
or rename as as Apache HTTPD?

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57287] Sort files listed by DefaultServlet

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=57287

--- Comment #3 from Oleg Trokhov <ot...@minsk.ximxim.com> ---
Created attachment 32248
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=32248&action=edit
Bug_57287 patch

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57287] Sort files listed by DefaultServlet

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=57287

--- Comment #8 from Konstantin Kolinko <kn...@gmail.com> ---
It can be more simple, with a single parameter such as
s=NA
s=ND
(sort Name ascending, Name descending)

A shorter parameter name makes it less obvious that the name is English one,
better for i18n point of view.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57287] Sort files listed by DefaultServlet

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=57287

--- Comment #4 from Oleg Trokhov <ot...@minsk.ximxim.com> ---
Hi. I added patch with some changes in DefaultServlet. Now by default sorting
is Alphabetic ascending, directory first.User can add parameters to http
request to configure sorting:
1. http://localhost:8080/?name=asc
2. http://localhost:8080/?name=dsc
3. http://localhost:8080/?size=asc
4. http://localhost:8080/?size=dsc
5. http://localhost:8080/?modify=asc
6. http://localhost:8080/?modify=dsc

Please tell if you have some suggestion or correction in code. And if you apply
this change, where is documentation for this functions?

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57287] Sort files listed by DefaultServlet

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=57287

--- Comment #7 from Violeta Georgieva <vi...@apache.org> ---
(In reply to Oleg Trokhov from comment #6)
> Created attachment 32249 [details]
> sorting list
> 
> I refactor import, so checkstyle task passed. So we leave my parameter
> naming or rename as as Apache HTTPD?

+1 for query string as Apache HTTPD

Regards,
Violeta

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57287] Sort files listed by DefaultServlet

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=57287

--- Comment #9 from Oleg Trokhov <ot...@minsk.ximxim.com> ---
Created attachment 32260
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=32260&action=edit
Bug 57287v3

Now with patch v3:
1. "s=NA" name=asc
2. "s=ND" name=dsc
3. "s=SA" size=asc
4. "s=SD" size=dsc
5. "s=MA" modify=asc
6. "s=MD" modify=dsc

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57287] Sort files listed by DefaultServlet

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=57287

--- Comment #5 from Konstantin Kolinko <kn...@gmail.com> ---
1. The code have to pass checkstyle rules (see BUILDING.txt on details on how
enable checkstyle). One of rules: no ".*" imports.

2. I thought of using the same parameters as Apache HTTPD,
They use query strings like C=N;O=A
C column (N name, M last modified, S size, D description - absent in Tomcat)
O order (A ascending, D descending)

Your parameter naming with a single parameter also looks OK.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57287] Sort files listed by DefaultServlet

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=57287

--- Comment #1 from Christopher Schultz <ch...@christopherschultz.net> ---
+1 to "dirs first"

Arguments can be had about whether or not sorting should be done case-sensitive
of case-insensitive.

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57287] Sort files listed by DefaultServlet

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=57287

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All
           Severity|normal                      |enhancement

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 57287] Sort files listed by DefaultServlet

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=57287

--- Comment #2 from Christopher Schultz <ch...@christopherschultz.net> ---
I also think that sorting should be optional and not enabled by default: large
directories could be problematic for performance and memory usage.

Or maybe there could be a setting that doesn't sort "directories" with more
than a certain number of items (1k?)

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org