MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / sortFileList

Function sortFileList

agent/utils/files/fileinfo.go:255–288  ·  view source on GitHub ↗
(list []FileSearchInfo, sortBy, sortOrder string)

Source from the content-addressed store, hash-verified

253}
254
255func sortFileList(list []FileSearchInfo, sortBy, sortOrder string) {
256 switch sortBy {
257 case "name":
258 if sortOrder == "ascending" {
259 sort.Slice(list, func(i, j int) bool {
260 return list[i].Name() < list[j].Name()
261 })
262 } else {
263 sort.Slice(list, func(i, j int) bool {
264 return list[i].Name() > list[j].Name()
265 })
266 }
267 case "size":
268 if sortOrder == "ascending" {
269 sort.Slice(list, func(i, j int) bool {
270 return list[i].Size() < list[j].Size()
271 })
272 } else {
273 sort.Slice(list, func(i, j int) bool {
274 return list[i].Size() > list[j].Size()
275 })
276 }
277 case "modTime":
278 if sortOrder == "ascending" {
279 sort.Slice(list, func(i, j int) bool {
280 return list[i].ModTime().Before(list[j].ModTime())
281 })
282 } else {
283 sort.Slice(list, func(i, j int) bool {
284 return list[i].ModTime().After(list[j].ModTime())
285 })
286 }
287 }
288}
289
290func (f *FileInfo) listChildren(option FileOption) error {
291 var (

Callers 1

getFilesMethod · 0.70

Calls 3

ModTimeMethod · 0.80
NameMethod · 0.65
SizeMethod · 0.65

Tested by

no test coverage detected