浏览代码

lib/db,cmd/stindex: Expose VersionList and use it in stindex

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3231
Audrius Butkevicius 9 年之前
父节点
当前提交
6f63909c65
共有 5 个文件被更改,包括 21 次插入19 次删除
  1. 3 1
      cmd/stindex/dump.go
  2. 2 2
      lib/db/leveldb.go
  3. 6 6
      lib/db/leveldb_dbinstance.go
  4. 2 2
      lib/db/leveldb_transactions.go
  5. 8 8
      lib/db/leveldb_xdr.go

+ 3 - 1
cmd/stindex/dump.go

@@ -39,7 +39,9 @@ func dump(ldb *leveldb.DB) {
 		case db.KeyTypeGlobal:
 			folder := nulString(key[1 : 1+64])
 			name := nulString(key[1+64:])
-			fmt.Printf("[global] F:%q N:%q V:%x\n", folder, name, it.Value())
+			var flv db.VersionList
+			flv.UnmarshalXDR(it.Value())
+			fmt.Printf("[global] F:%q N:%q V: %s\n", folder, name, flv)
 
 		case db.KeyTypeBlock:
 			folder := nulString(key[1 : 1+64])

+ 2 - 2
lib/db/leveldb.go

@@ -51,11 +51,11 @@ type fileVersion struct {
 	device  []byte
 }
 
-type versionList struct {
+type VersionList struct {
 	versions []fileVersion
 }
 
-func (l versionList) String() string {
+func (l VersionList) String() string {
 	var b bytes.Buffer
 	var id protocol.DeviceID
 	b.WriteString("{")

+ 6 - 6
lib/db/leveldb_dbinstance.go

@@ -339,7 +339,7 @@ func (db *Instance) getGlobal(folder, file []byte, truncate bool) (FileIntf, boo
 		panic(err)
 	}
 
-	var vl versionList
+	var vl VersionList
 	err = vl.UnmarshalXDR(bs)
 	if err != nil {
 		panic(err)
@@ -376,7 +376,7 @@ func (db *Instance) withGlobal(folder, prefix []byte, truncate bool, fn Iterator
 
 	var fk []byte
 	for dbi.Next() {
-		var vl versionList
+		var vl VersionList
 		err := vl.UnmarshalXDR(dbi.Value())
 		if err != nil {
 			panic(err)
@@ -428,7 +428,7 @@ func (db *Instance) availability(folder, file []byte) []protocol.DeviceID {
 		panic(err)
 	}
 
-	var vl versionList
+	var vl VersionList
 	err = vl.UnmarshalXDR(bs)
 	if err != nil {
 		panic(err)
@@ -456,7 +456,7 @@ func (db *Instance) withNeed(folder, device []byte, truncate bool, fn Iterator)
 	var fk []byte
 nextFile:
 	for dbi.Next() {
-		var vl versionList
+		var vl VersionList
 		err := vl.UnmarshalXDR(dbi.Value())
 		if err != nil {
 			panic(err)
@@ -593,7 +593,7 @@ func (db *Instance) checkGlobals(folder []byte, globalSize *sizeTracker) {
 	var fk []byte
 	for dbi.Next() {
 		gk := dbi.Key()
-		var vl versionList
+		var vl VersionList
 		err := vl.UnmarshalXDR(dbi.Value())
 		if err != nil {
 			panic(err)
@@ -605,7 +605,7 @@ func (db *Instance) checkGlobals(folder []byte, globalSize *sizeTracker) {
 		// we find those and clear them out.
 
 		name := db.globalKeyName(gk)
-		var newVL versionList
+		var newVL VersionList
 		for i, version := range vl.versions {
 			fk = db.deviceKeyInto(fk[:cap(fk)], folder, version.device, name)
 

+ 2 - 2
lib/db/leveldb_transactions.go

@@ -96,7 +96,7 @@ func (t readWriteTransaction) updateGlobal(folder, device []byte, file protocol.
 		panic(err)
 	}
 
-	var fl versionList
+	var fl VersionList
 	var oldFile protocol.FileInfo
 	var hasOldFile bool
 	// Remove the device from the current version list
@@ -205,7 +205,7 @@ func (t readWriteTransaction) removeFromGlobal(folder, device, file []byte, glob
 		return
 	}
 
-	var fl versionList
+	var fl VersionList
 	err = fl.UnmarshalXDR(svl)
 	if err != nil {
 		panic(err)

+ 8 - 8
lib/db/leveldb_xdr.go

@@ -71,7 +71,7 @@ func (o *fileVersion) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
 
 /*
 
-versionList Structure:
+VersionList Structure:
 
  0                   1                   2                   3
  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@@ -84,23 +84,23 @@ versionList Structure:
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 
 
-struct versionList {
+struct VersionList {
 	fileVersion versions<>;
 }
 
 */
 
-func (o versionList) XDRSize() int {
+func (o VersionList) XDRSize() int {
 	return 4 + xdr.SizeOfSlice(o.versions)
 }
 
-func (o versionList) MarshalXDR() ([]byte, error) {
+func (o VersionList) MarshalXDR() ([]byte, error) {
 	buf := make([]byte, o.XDRSize())
 	m := &xdr.Marshaller{Data: buf}
 	return buf, o.MarshalXDRInto(m)
 }
 
-func (o versionList) MustMarshalXDR() []byte {
+func (o VersionList) MustMarshalXDR() []byte {
 	bs, err := o.MarshalXDR()
 	if err != nil {
 		panic(err)
@@ -108,7 +108,7 @@ func (o versionList) MustMarshalXDR() []byte {
 	return bs
 }
 
-func (o versionList) MarshalXDRInto(m *xdr.Marshaller) error {
+func (o VersionList) MarshalXDRInto(m *xdr.Marshaller) error {
 	m.MarshalUint32(uint32(len(o.versions)))
 	for i := range o.versions {
 		if err := o.versions[i].MarshalXDRInto(m); err != nil {
@@ -118,11 +118,11 @@ func (o versionList) MarshalXDRInto(m *xdr.Marshaller) error {
 	return m.Error
 }
 
-func (o *versionList) UnmarshalXDR(bs []byte) error {
+func (o *VersionList) UnmarshalXDR(bs []byte) error {
 	u := &xdr.Unmarshaller{Data: bs}
 	return o.UnmarshalXDRFrom(u)
 }
-func (o *versionList) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
+func (o *VersionList) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
 	_versionsSize := int(u.UnmarshalUint32())
 	if _versionsSize < 0 {
 		return xdr.ElementSizeExceeded("versions", _versionsSize, 0)