Allow prioritization of downloads based on name (fixes #174)

This commit is contained in:
Arthur Axel 'fREW' Schmidt
2014-06-06 22:10:15 -05:00
committed by Jakob Borg
parent df381fd03f
commit 82cfd37263
5 changed files with 188 additions and 8 deletions

34
files/sort.go Normal file
View File

@@ -0,0 +1,34 @@
package files
import (
"sort"
"github.com/calmh/syncthing/scanner"
)
type SortBy func(p scanner.File) int
func (by SortBy) Sort(files []scanner.File) {
ps := &fileSorter{
files: files,
by: by,
}
sort.Sort(ps)
}
type fileSorter struct {
files []scanner.File
by func(p1 scanner.File) int
}
func (s *fileSorter) Len() int {
return len(s.files)
}
func (s *fileSorter) Swap(i, j int) {
s.files[i], s.files[j] = s.files[j], s.files[i]
}
func (s *fileSorter) Less(i, j int) bool {
return s.by(s.files[i]) > s.by(s.files[j])
}