Exemple #1
0
// NeedFiles returns the list of currently needed files and the total size.
func (m *Model) NeedFilesRepo(repo string) []scanner.File {
	m.rmut.RLock()
	defer m.rmut.RUnlock()
	if rf, ok := m.repoFiles[repo]; ok {
		f := rf.Need(cid.LocalID)
		if r := m.repoCfgs[repo].FileRanker(); r != nil {
			files.SortBy(r).Sort(f)
		}
		return f
	}
	return nil
}
Exemple #2
0
func TestFileSorter(t *testing.T) {
	rcfg := RepositoryConfiguration{
		SyncOrderPatterns: []SyncOrderPattern{
			{"\\.jpg$", 10, nil},
			{"\\.mov$", 5, nil},
			{"^camera-uploads", 100, nil},
		},
	}

	f := []scanner.File{
		{Name: "bar.mov"},
		{Name: "baz.txt"},
		{Name: "foo.jpg"},
		{Name: "frew/foo.jpg"},
		{Name: "frew/lol.go"},
		{Name: "frew/rofl.copter"},
		{Name: "frew/bar.mov"},
		{Name: "camera-uploads/foo.jpg"},
		{Name: "camera-uploads/hurr.pl"},
		{Name: "camera-uploads/herp.mov"},
		{Name: "camera-uploads/wee.txt"},
	}

	files.SortBy(rcfg.FileRanker()).Sort(f)

	expected := []scanner.File{
		{Name: "camera-uploads/foo.jpg"},
		{Name: "camera-uploads/herp.mov"},
		{Name: "camera-uploads/hurr.pl"},
		{Name: "camera-uploads/wee.txt"},
		{Name: "foo.jpg"},
		{Name: "frew/foo.jpg"},
		{Name: "bar.mov"},
		{Name: "frew/bar.mov"},
		{Name: "frew/lol.go"},
		{Name: "baz.txt"},
		{Name: "frew/rofl.copter"},
	}

	if !reflect.DeepEqual(f, expected) {
		t.Errorf(
			"\n\nexpected:\n" +
				formatFiles(expected) + "\n" +
				"got:\n" +
				formatFiles(f) + "\n\n",
		)
	}
}
Exemple #3
0
// NeedFiles returns the list of currently needed files
func (m *Model) NeedFilesRepo(repo string) []protocol.FileInfo {
	m.rmut.RLock()
	defer m.rmut.RUnlock()
	if rf, ok := m.repoFiles[repo]; ok {
		fs := make([]protocol.FileInfo, 0, indexBatchSize)
		rf.WithNeed(protocol.LocalNodeID, func(f protocol.FileInfo) bool {
			fs = append(fs, f)
			return len(fs) < indexBatchSize
		})
		if r := m.repoCfgs[repo].FileRanker(); r != nil {
			files.SortBy(r).Sort(fs)
		}
		return fs
	}
	return nil
}
Exemple #4
0
// NeedFiles returns the list of currently needed files
func (m *Model) NeedFilesRepo(repo string) []scanner.File {
	m.rmut.RLock()
	defer m.rmut.RUnlock()
	if rf, ok := m.repoFiles[repo]; ok {
		var fs []scanner.File
		rf.WithNeed(protocol.LocalNodeID, func(f scanner.File) bool {
			fs = append(fs, f)
			return true
		})
		if r := m.repoCfgs[repo].FileRanker(); r != nil {
			files.SortBy(r).Sort(fs)
		}
		return fs
	}
	return nil
}