瀏覽代碼

Rename db.Set to db.FileSet

Jakob Borg 11 年之前
父節點
當前提交
e6c9baf6ef
共有 5 個文件被更改,包括 45 次插入45 次删除
  1. 1 1
      cmd/stindex/main.go
  2. 1 1
      cmd/syncthing/main_test.go
  3. 17 17
      internal/db/set.go
  4. 21 21
      internal/db/set_test.go
  5. 5 5
      internal/model/model.go

+ 1 - 1
cmd/stindex/main.go

@@ -39,7 +39,7 @@ func main() {
 		log.Fatal(err)
 	}
 
-	fs := db.NewSet(*folder, ldb)
+	fs := db.NewFileSet(*folder, ldb)
 
 	if *device == "" {
 		log.Printf("*** Global index for folder %q", *folder)

+ 1 - 1
cmd/syncthing/main_test.go

@@ -91,7 +91,7 @@ func TestSanityCheck(t *testing.T) {
 
 	// Case 3 - marker missing
 
-	set := db.NewSet("folder", ldb)
+	set := db.NewFileSet("folder", ldb)
 	set.Update(protocol.LocalDeviceID, []protocol.FileInfo{
 		{Name: "dummyfile"},
 	})

+ 17 - 17
internal/db/set.go

@@ -30,7 +30,7 @@ import (
 	"github.com/syndtr/goleveldb/leveldb"
 )
 
-type Set struct {
+type FileSet struct {
 	localVersion map[protocol.DeviceID]uint64
 	mutex        sync.Mutex
 	folder       string
@@ -54,8 +54,8 @@ type FileIntf interface {
 // continue iteration, false to stop.
 type Iterator func(f FileIntf) bool
 
-func NewSet(folder string, db *leveldb.DB) *Set {
-	var s = Set{
+func NewFileSet(folder string, db *leveldb.DB) *FileSet {
+	var s = FileSet{
 		localVersion: make(map[protocol.DeviceID]uint64),
 		folder:       folder,
 		db:           db,
@@ -81,7 +81,7 @@ func NewSet(folder string, db *leveldb.DB) *Set {
 	return &s
 }
 
-func (s *Set) Replace(device protocol.DeviceID, fs []protocol.FileInfo) {
+func (s *FileSet) Replace(device protocol.DeviceID, fs []protocol.FileInfo) {
 	if debug {
 		l.Debugf("%s Replace(%v, [%d])", s.folder, device, len(fs))
 	}
@@ -99,7 +99,7 @@ func (s *Set) Replace(device protocol.DeviceID, fs []protocol.FileInfo) {
 	}
 }
 
-func (s *Set) ReplaceWithDelete(device protocol.DeviceID, fs []protocol.FileInfo) {
+func (s *FileSet) ReplaceWithDelete(device protocol.DeviceID, fs []protocol.FileInfo) {
 	if debug {
 		l.Debugf("%s ReplaceWithDelete(%v, [%d])", s.folder, device, len(fs))
 	}
@@ -115,7 +115,7 @@ func (s *Set) ReplaceWithDelete(device protocol.DeviceID, fs []protocol.FileInfo
 	}
 }
 
-func (s *Set) Update(device protocol.DeviceID, fs []protocol.FileInfo) {
+func (s *FileSet) Update(device protocol.DeviceID, fs []protocol.FileInfo) {
 	if debug {
 		l.Debugf("%s Update(%v, [%d])", s.folder, device, len(fs))
 	}
@@ -140,55 +140,55 @@ func (s *Set) Update(device protocol.DeviceID, fs []protocol.FileInfo) {
 	}
 }
 
-func (s *Set) WithNeed(device protocol.DeviceID, fn Iterator) {
+func (s *FileSet) WithNeed(device protocol.DeviceID, fn Iterator) {
 	if debug {
 		l.Debugf("%s WithNeed(%v)", s.folder, device)
 	}
 	ldbWithNeed(s.db, []byte(s.folder), device[:], false, nativeFileIterator(fn))
 }
 
-func (s *Set) WithNeedTruncated(device protocol.DeviceID, fn Iterator) {
+func (s *FileSet) WithNeedTruncated(device protocol.DeviceID, fn Iterator) {
 	if debug {
 		l.Debugf("%s WithNeedTruncated(%v)", s.folder, device)
 	}
 	ldbWithNeed(s.db, []byte(s.folder), device[:], true, nativeFileIterator(fn))
 }
 
-func (s *Set) WithHave(device protocol.DeviceID, fn Iterator) {
+func (s *FileSet) WithHave(device protocol.DeviceID, fn Iterator) {
 	if debug {
 		l.Debugf("%s WithHave(%v)", s.folder, device)
 	}
 	ldbWithHave(s.db, []byte(s.folder), device[:], false, nativeFileIterator(fn))
 }
 
-func (s *Set) WithHaveTruncated(device protocol.DeviceID, fn Iterator) {
+func (s *FileSet) WithHaveTruncated(device protocol.DeviceID, fn Iterator) {
 	if debug {
 		l.Debugf("%s WithHaveTruncated(%v)", s.folder, device)
 	}
 	ldbWithHave(s.db, []byte(s.folder), device[:], true, nativeFileIterator(fn))
 }
 
-func (s *Set) WithGlobal(fn Iterator) {
+func (s *FileSet) WithGlobal(fn Iterator) {
 	if debug {
 		l.Debugf("%s WithGlobal()", s.folder)
 	}
 	ldbWithGlobal(s.db, []byte(s.folder), false, nativeFileIterator(fn))
 }
 
-func (s *Set) WithGlobalTruncated(fn Iterator) {
+func (s *FileSet) WithGlobalTruncated(fn Iterator) {
 	if debug {
 		l.Debugf("%s WithGlobalTruncated()", s.folder)
 	}
 	ldbWithGlobal(s.db, []byte(s.folder), true, nativeFileIterator(fn))
 }
 
-func (s *Set) Get(device protocol.DeviceID, file string) (protocol.FileInfo, bool) {
+func (s *FileSet) Get(device protocol.DeviceID, file string) (protocol.FileInfo, bool) {
 	f, ok := ldbGet(s.db, []byte(s.folder), device[:], []byte(osutil.NormalizedFilename(file)))
 	f.Name = osutil.NativeFilename(f.Name)
 	return f, ok
 }
 
-func (s *Set) GetGlobal(file string) (protocol.FileInfo, bool) {
+func (s *FileSet) GetGlobal(file string) (protocol.FileInfo, bool) {
 	fi, ok := ldbGetGlobal(s.db, []byte(s.folder), []byte(osutil.NormalizedFilename(file)), false)
 	if !ok {
 		return protocol.FileInfo{}, false
@@ -198,7 +198,7 @@ func (s *Set) GetGlobal(file string) (protocol.FileInfo, bool) {
 	return f, true
 }
 
-func (s *Set) GetGlobalTruncated(file string) (FileInfoTruncated, bool) {
+func (s *FileSet) GetGlobalTruncated(file string) (FileInfoTruncated, bool) {
 	fi, ok := ldbGetGlobal(s.db, []byte(s.folder), []byte(osutil.NormalizedFilename(file)), true)
 	if !ok {
 		return FileInfoTruncated{}, false
@@ -208,11 +208,11 @@ func (s *Set) GetGlobalTruncated(file string) (FileInfoTruncated, bool) {
 	return f, true
 }
 
-func (s *Set) Availability(file string) []protocol.DeviceID {
+func (s *FileSet) Availability(file string) []protocol.DeviceID {
 	return ldbAvailability(s.db, []byte(s.folder), []byte(osutil.NormalizedFilename(file)))
 }
 
-func (s *Set) LocalVersion(device protocol.DeviceID) uint64 {
+func (s *FileSet) LocalVersion(device protocol.DeviceID) uint64 {
 	s.mutex.Lock()
 	defer s.mutex.Unlock()
 	return s.localVersion[device]

+ 21 - 21
internal/db/set_test.go

@@ -49,7 +49,7 @@ func genBlocks(n int) []protocol.BlockInfo {
 	return b
 }
 
-func globalList(s *db.Set) []protocol.FileInfo {
+func globalList(s *db.FileSet) []protocol.FileInfo {
 	var fs []protocol.FileInfo
 	s.WithGlobal(func(fi db.FileIntf) bool {
 		f := fi.(protocol.FileInfo)
@@ -59,7 +59,7 @@ func globalList(s *db.Set) []protocol.FileInfo {
 	return fs
 }
 
-func haveList(s *db.Set, n protocol.DeviceID) []protocol.FileInfo {
+func haveList(s *db.FileSet, n protocol.DeviceID) []protocol.FileInfo {
 	var fs []protocol.FileInfo
 	s.WithHave(n, func(fi db.FileIntf) bool {
 		f := fi.(protocol.FileInfo)
@@ -69,7 +69,7 @@ func haveList(s *db.Set, n protocol.DeviceID) []protocol.FileInfo {
 	return fs
 }
 
-func needList(s *db.Set, n protocol.DeviceID) []protocol.FileInfo {
+func needList(s *db.FileSet, n protocol.DeviceID) []protocol.FileInfo {
 	var fs []protocol.FileInfo
 	s.WithNeed(n, func(fi db.FileIntf) bool {
 		f := fi.(protocol.FileInfo)
@@ -111,7 +111,7 @@ func TestGlobalSet(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	m := db.NewSet("test", ldb)
+	m := db.NewFileSet("test", ldb)
 
 	local0 := fileList{
 		protocol.FileInfo{Name: "a", Version: 1000, Blocks: genBlocks(1)},
@@ -272,7 +272,7 @@ func TestNeedWithInvalid(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	s := db.NewSet("test", ldb)
+	s := db.NewFileSet("test", ldb)
 
 	localHave := fileList{
 		protocol.FileInfo{Name: "a", Version: 1000, Blocks: genBlocks(1)},
@@ -314,7 +314,7 @@ func TestUpdateToInvalid(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	s := db.NewSet("test", ldb)
+	s := db.NewFileSet("test", ldb)
 
 	localHave := fileList{
 		protocol.FileInfo{Name: "a", Version: 1000, Blocks: genBlocks(1)},
@@ -351,7 +351,7 @@ func TestInvalidAvailability(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	s := db.NewSet("test", ldb)
+	s := db.NewFileSet("test", ldb)
 
 	remote0Have := fileList{
 		protocol.FileInfo{Name: "both", Version: 1001, Blocks: genBlocks(2)},
@@ -391,7 +391,7 @@ func TestLocalDeleted(t *testing.T) {
 	if err != nil {
 		t.Fatal(err)
 	}
-	m := db.NewSet("test", ldb)
+	m := db.NewFileSet("test", ldb)
 	lamport.Default = lamport.Clock{}
 
 	local1 := []protocol.FileInfo{
@@ -474,7 +474,7 @@ func Benchmark10kReplace(b *testing.B) {
 
 	b.ResetTimer()
 	for i := 0; i < b.N; i++ {
-		m := db.NewSet("test", ldb)
+		m := db.NewFileSet("test", ldb)
 		m.ReplaceWithDelete(protocol.LocalDeviceID, local)
 	}
 }
@@ -490,7 +490,7 @@ func Benchmark10kUpdateChg(b *testing.B) {
 		b.Fatal(err)
 	}
 
-	m := db.NewSet("test", ldb)
+	m := db.NewFileSet("test", ldb)
 	m.Replace(remoteDevice0, remote)
 
 	var local []protocol.FileInfo
@@ -521,7 +521,7 @@ func Benchmark10kUpdateSme(b *testing.B) {
 	if err != nil {
 		b.Fatal(err)
 	}
-	m := db.NewSet("test", ldb)
+	m := db.NewFileSet("test", ldb)
 	m.Replace(remoteDevice0, remote)
 
 	var local []protocol.FileInfo
@@ -548,7 +548,7 @@ func Benchmark10kNeed2k(b *testing.B) {
 		b.Fatal(err)
 	}
 
-	m := db.NewSet("test", ldb)
+	m := db.NewFileSet("test", ldb)
 	m.Replace(remoteDevice0, remote)
 
 	var local []protocol.FileInfo
@@ -581,7 +581,7 @@ func Benchmark10kHaveFullList(b *testing.B) {
 		b.Fatal(err)
 	}
 
-	m := db.NewSet("test", ldb)
+	m := db.NewFileSet("test", ldb)
 	m.Replace(remoteDevice0, remote)
 
 	var local []protocol.FileInfo
@@ -614,7 +614,7 @@ func Benchmark10kGlobal(b *testing.B) {
 		b.Fatal(err)
 	}
 
-	m := db.NewSet("test", ldb)
+	m := db.NewFileSet("test", ldb)
 	m.Replace(remoteDevice0, remote)
 
 	var local []protocol.FileInfo
@@ -642,7 +642,7 @@ func TestGlobalReset(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	m := db.NewSet("test", ldb)
+	m := db.NewFileSet("test", ldb)
 
 	local := []protocol.FileInfo{
 		{Name: "a", Version: 1000},
@@ -683,7 +683,7 @@ func TestNeed(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	m := db.NewSet("test", ldb)
+	m := db.NewFileSet("test", ldb)
 
 	local := []protocol.FileInfo{
 		{Name: "a", Version: 1000},
@@ -724,7 +724,7 @@ func TestLocalVersion(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	m := db.NewSet("test", ldb)
+	m := db.NewFileSet("test", ldb)
 
 	local1 := []protocol.FileInfo{
 		{Name: "a", Version: 1000},
@@ -763,7 +763,7 @@ func TestListDropFolder(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	s0 := db.NewSet("test0", ldb)
+	s0 := db.NewFileSet("test0", ldb)
 	local1 := []protocol.FileInfo{
 		{Name: "a", Version: 1000},
 		{Name: "b", Version: 1000},
@@ -771,7 +771,7 @@ func TestListDropFolder(t *testing.T) {
 	}
 	s0.Replace(protocol.LocalDeviceID, local1)
 
-	s1 := db.NewSet("test1", ldb)
+	s1 := db.NewFileSet("test1", ldb)
 	local2 := []protocol.FileInfo{
 		{Name: "d", Version: 1002},
 		{Name: "e", Version: 1002},
@@ -814,7 +814,7 @@ func TestGlobalNeedWithInvalid(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	s := db.NewSet("test1", ldb)
+	s := db.NewFileSet("test1", ldb)
 
 	rem0 := fileList{
 		protocol.FileInfo{Name: "a", Version: 1002, Blocks: genBlocks(4)},
@@ -854,7 +854,7 @@ func TestLongPath(t *testing.T) {
 		t.Fatal(err)
 	}
 
-	s := db.NewSet("test", ldb)
+	s := db.NewFileSet("test", ldb)
 
 	var b bytes.Buffer
 	for i := 0; i < 100; i++ {

+ 5 - 5
internal/model/model.go

@@ -94,7 +94,7 @@ type Model struct {
 	clientVersion string
 
 	folderCfgs     map[string]config.FolderConfiguration                  // folder -> cfg
-	folderFiles    map[string]*db.Set                                     // folder -> files
+	folderFiles    map[string]*db.FileSet                                 // folder -> files
 	folderDevices  map[string][]protocol.DeviceID                         // folder -> deviceIDs
 	deviceFolders  map[protocol.DeviceID][]string                         // deviceID -> folders
 	deviceStatRefs map[protocol.DeviceID]*stats.DeviceStatisticsReference // deviceID -> statsRef
@@ -134,7 +134,7 @@ func NewModel(cfg *config.Wrapper, deviceName, clientName, clientVersion string,
 		clientName:         clientName,
 		clientVersion:      clientVersion,
 		folderCfgs:         make(map[string]config.FolderConfiguration),
-		folderFiles:        make(map[string]*db.Set),
+		folderFiles:        make(map[string]*db.FileSet),
 		folderDevices:      make(map[string][]protocol.DeviceID),
 		deviceFolders:      make(map[protocol.DeviceID][]string),
 		deviceStatRefs:     make(map[protocol.DeviceID]*stats.DeviceStatisticsReference),
@@ -949,7 +949,7 @@ func (m *Model) receivedFile(folder, filename string) {
 	m.folderStatRef(folder).ReceivedFile(filename)
 }
 
-func sendIndexes(conn protocol.Connection, folder string, fs *db.Set, ignores *ignore.Matcher) {
+func sendIndexes(conn protocol.Connection, folder string, fs *db.FileSet, ignores *ignore.Matcher) {
 	deviceID := conn.ID()
 	name := conn.Name()
 	var err error
@@ -974,7 +974,7 @@ func sendIndexes(conn protocol.Connection, folder string, fs *db.Set, ignores *i
 	}
 }
 
-func sendIndexTo(initial bool, minLocalVer uint64, conn protocol.Connection, folder string, fs *db.Set, ignores *ignore.Matcher) (uint64, error) {
+func sendIndexTo(initial bool, minLocalVer uint64, conn protocol.Connection, folder string, fs *db.FileSet, ignores *ignore.Matcher) (uint64, error) {
 	deviceID := conn.ID()
 	name := conn.Name()
 	batch := make([]protocol.FileInfo, 0, indexBatchSize)
@@ -1081,7 +1081,7 @@ func (m *Model) AddFolder(cfg config.FolderConfiguration) {
 
 	m.fmut.Lock()
 	m.folderCfgs[cfg.ID] = cfg
-	m.folderFiles[cfg.ID] = db.NewSet(cfg.ID, m.db)
+	m.folderFiles[cfg.ID] = db.NewFileSet(cfg.ID, m.db)
 
 	m.folderDevices[cfg.ID] = make([]protocol.DeviceID, len(cfg.Devices))
 	for i, device := range cfg.Devices {