mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
browse: When sorting by size, offset directories
Assigns negative sizes to directories in order to have them listed reliably before any zero-sized files. That order is what most users expect when sorting by size. As side effect directories will appear before files on all filesystem implementations. To give an example: before this change directories had a size of 4 KiB when using Linux with ext4 or tmpfs, and with ZFS a size resembling an estimation of the number of leaves within said directory.
This commit is contained in:
parent
1d38d113f8
commit
239f6825f7
1 changed files with 14 additions and 3 deletions
|
@ -137,7 +137,18 @@ func (l byName) Less(i, j int) bool {
|
|||
// By Size
|
||||
func (l bySize) Len() int { return len(l.Items) }
|
||||
func (l bySize) Swap(i, j int) { l.Items[i], l.Items[j] = l.Items[j], l.Items[i] }
|
||||
func (l bySize) Less(i, j int) bool { return l.Items[i].Size < l.Items[j].Size }
|
||||
|
||||
const directoryOffset = -1 << 31 // = math.MinInt32
|
||||
func (l bySize) Less(i, j int) bool {
|
||||
iSize, jSize := l.Items[i].Size, l.Items[j].Size
|
||||
if l.Items[i].IsDir {
|
||||
iSize = directoryOffset + iSize
|
||||
}
|
||||
if l.Items[j].IsDir {
|
||||
jSize = directoryOffset + jSize
|
||||
}
|
||||
return iSize < jSize
|
||||
}
|
||||
|
||||
// By Time
|
||||
func (l byTime) Len() int { return len(l.Items) }
|
||||
|
|
Loading…
Reference in a new issue