Skip to content

Commit 5678daa

Browse files
committed
feat(serverHandler): unify name comparing logic
1 parent c912221 commit 5678daa

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/serverHandler/sort.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var cmpDirLast fnCompareDir = func(prev, next os.FileInfo) (less, ok bool) {
2525
prevIsDir := prev.IsDir()
2626
nextIsDir := next.IsDir()
2727
if prevIsDir != nextIsDir {
28-
return !prevIsDir, true
28+
return nextIsDir, true
2929
}
3030
return true, false
3131
}
@@ -232,9 +232,9 @@ func (infos infosSizeAsc) Less(i, j int) bool {
232232
return items[i].Size() < items[j].Size()
233233
}
234234

235-
cmpResult := strings.Compare(items[i].Name(), items[j].Name())
236-
if cmpResult != 0 {
237-
return cmpResult < 0
235+
less, ok = util.CompareNumInFilename([]byte(items[i].Name()), []byte(items[j].Name()))
236+
if ok {
237+
return less
238238
}
239239

240240
return i < j
@@ -262,9 +262,9 @@ func (infos infosSizeDesc) Less(i, j int) bool {
262262
return items[j].Size() < items[i].Size()
263263
}
264264

265-
cmpResult := strings.Compare(items[j].Name(), items[i].Name())
266-
if cmpResult != 0 {
267-
return cmpResult < 0
265+
less, ok = util.CompareNumInFilename([]byte(items[j].Name()), []byte(items[i].Name()))
266+
if ok {
267+
return less
268268
}
269269

270270
return j < i
@@ -292,9 +292,9 @@ func (infos infosTimeAsc) Less(i, j int) bool {
292292
return items[i].ModTime().Before(items[j].ModTime())
293293
}
294294

295-
cmpResult := strings.Compare(items[i].Name(), items[j].Name())
296-
if cmpResult != 0 {
297-
return cmpResult < 0
295+
less, ok = util.CompareNumInFilename([]byte(items[i].Name()), []byte(items[j].Name()))
296+
if ok {
297+
return less
298298
}
299299

300300
return i < j
@@ -322,9 +322,9 @@ func (infos infosTimeDesc) Less(i, j int) bool {
322322
return items[j].ModTime().Before(items[i].ModTime())
323323
}
324324

325-
cmpResult := strings.Compare(items[j].Name(), items[i].Name())
326-
if cmpResult != 0 {
327-
return cmpResult < 0
325+
less, ok = util.CompareNumInFilename([]byte(items[j].Name()), []byte(items[i].Name()))
326+
if ok {
327+
return less
328328
}
329329

330330
return j < i

0 commit comments

Comments
 (0)