mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-31 02:27:19 -04: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
					
				| @ -135,9 +135,20 @@ func (l byName) Less(i, j int) bool { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // By Size | // By Size | ||||||
| func (l bySize) Len() int           { return len(l.Items) } | 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) 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 | // By Time | ||||||
| func (l byTime) Len() int           { return len(l.Items) } | func (l byTime) Len() int           { return len(l.Items) } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user