cabinet/internal/gc/sort.go

25 lines
465 B
Go
Raw Normal View History

package gc
import (
"os"
"time"
)
type sorter []os.FileInfo
func (f sorter) Len() int {
return len(f)
}
func (f sorter) Less(i, j int) bool {
// Snagged this from chanbakjsd/filehost
const bytesPerSecond = 1024
fi := int(time.Since(f[i].ModTime()).Seconds()) + int(f[i].Size()/bytesPerSecond)
fj := int(time.Since(f[j].ModTime()).Seconds()) + int(f[j].Size()/bytesPerSecond)
return fi > fj
}
func (f sorter) Swap(i, j int) {
f[i], f[j] = f[j], f[i]
}