Skip to content
Snippets Groups Projects
Commit 1c15e56f authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Fix issues with file sorting

The case-sensitive/insensitive logic was backwards
(-i enabled case-sensitive sorting)

The re-sorting by name was always occurring when the -sort option was used.

Case-insensitive sorting by numeric properties (e.g. size) didn't work right.
parent 61a116a1
No related branches found
No related tags found
No related merge requests found
...@@ -35,7 +35,7 @@ function is_user_accessible_dir(dir) ...@@ -35,7 +35,7 @@ function is_user_accessible_dir(dir)
} }
var out = js.global.stdout ? stdout : console; var out = js.global.stdout ? stdout : console;
var sort_prop = "name"; var sort_prop;
var exclude_list = []; var exclude_list = [];
var options = { sort: false, case_sensitive: true }; var options = { sort: false, case_sensitive: true };
var json_space; var json_space;
...@@ -308,8 +308,8 @@ for(var i = 0; i < dir_list.length; i++) { ...@@ -308,8 +308,8 @@ for(var i = 0; i < dir_list.length; i++) {
if(!file_list.length) if(!file_list.length)
exit(0); exit(0);
if(!options.hdr && options.sort) { if(!options.hdr && options.sort && sort_prop !== undefined) {
if(options.case_sensitive) { if(!options.case_sensitive) {
log("Sorting " + file_list.length + " files..."); log("Sorting " + file_list.length + " files...");
if(typeof file_list[0] == "string") if(typeof file_list[0] == "string")
file_list.sort( file_list.sort(
...@@ -322,8 +322,12 @@ if(!options.hdr && options.sort) { ...@@ -322,8 +322,12 @@ if(!options.hdr && options.sort) {
else { else {
file_list.sort( file_list.sort(
function(a, b) { function(a, b) {
var a = String(a[sort_prop]).toLowerCase(); var a = a[sort_prop];
var b = String(b[sort_prop]).toLowerCase(); var b = b[sort_prop];
if(typeof a == "string") {
var a = a.toLowerCase();
var b = b.toLowerCase();
}
if (a < b) return -1; if (a < b) return -1;
if (a > b) return 1; if (a > b) return 1;
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment