mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-03 19:17:29 -05:00 
			
		
		
		
	Merge pull request #1546 from wmark/browse-sort-size
browse: fix arbitrary ordering of directories with sort=size
This commit is contained in:
		
						commit
						e26a855d8b
					
				@ -165,12 +165,21 @@ func (l bySize) Swap(i, j int) { l.Items[i], l.Items[j] = l.Items[j], l.Items[i]
 | 
				
			|||||||
const directoryOffset = -1 << 31 // = math.MinInt32
 | 
					const directoryOffset = -1 << 31 // = math.MinInt32
 | 
				
			||||||
func (l bySize) Less(i, j int) bool {
 | 
					func (l bySize) Less(i, j int) bool {
 | 
				
			||||||
	iSize, jSize := l.Items[i].Size, l.Items[j].Size
 | 
						iSize, jSize := l.Items[i].Size, l.Items[j].Size
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Directory sizes depend on the filesystem implementation,
 | 
				
			||||||
 | 
						// which is opaque to a visitor, and should indeed does not change if the operator choses to change the fs.
 | 
				
			||||||
 | 
						// For a consistent user experience directories are pulled to the front…
 | 
				
			||||||
	if l.Items[i].IsDir {
 | 
						if l.Items[i].IsDir {
 | 
				
			||||||
		iSize = directoryOffset + iSize
 | 
							iSize = directoryOffset
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if l.Items[j].IsDir {
 | 
						if l.Items[j].IsDir {
 | 
				
			||||||
		jSize = directoryOffset + jSize
 | 
							jSize = directoryOffset
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						// … and sorted by name.
 | 
				
			||||||
 | 
						if l.Items[i].IsDir && l.Items[j].IsDir {
 | 
				
			||||||
 | 
							return strings.ToLower(l.Items[i].Name) < strings.ToLower(l.Items[j].Name)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return iSize < jSize
 | 
						return iSize < jSize
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user