2015-10-23 19:02:38 +00:00
|
|
|
// Copyright (C) 2015 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2015-10-23 19:02:38 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2016-08-06 13:05:59 +00:00
|
|
|
"time"
|
2015-10-23 19:02:38 +00:00
|
|
|
|
|
|
|
"github.com/syncthing/syncthing/lib/db"
|
2019-11-29 08:11:52 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/db/backend"
|
2015-10-23 19:21:21 +00:00
|
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
2015-10-23 19:02:38 +00:00
|
|
|
)
|
|
|
|
|
2019-11-29 08:11:52 +00:00
|
|
|
func dump(ldb backend.Backend) {
|
|
|
|
it, err := ldb.NewPrefixIterator(nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2015-10-23 19:02:38 +00:00
|
|
|
for it.Next() {
|
|
|
|
key := it.Key()
|
|
|
|
switch key[0] {
|
|
|
|
case db.KeyTypeDevice:
|
2016-07-04 10:40:29 +00:00
|
|
|
folder := binary.BigEndian.Uint32(key[1:])
|
|
|
|
device := binary.BigEndian.Uint32(key[1+4:])
|
|
|
|
name := nulString(key[1+4+4:])
|
|
|
|
fmt.Printf("[device] F:%d D:%d N:%q", folder, device, name)
|
2015-10-23 19:02:38 +00:00
|
|
|
|
|
|
|
var f protocol.FileInfo
|
2016-07-04 10:40:29 +00:00
|
|
|
err := f.Unmarshal(it.Value())
|
2015-10-23 19:02:38 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2016-07-04 10:40:29 +00:00
|
|
|
fmt.Printf(" V:%v\n", f)
|
2015-10-23 19:02:38 +00:00
|
|
|
|
|
|
|
case db.KeyTypeGlobal:
|
2016-07-04 10:40:29 +00:00
|
|
|
folder := binary.BigEndian.Uint32(key[1:])
|
|
|
|
name := nulString(key[1+4:])
|
2016-05-31 19:29:26 +00:00
|
|
|
var flv db.VersionList
|
2016-07-04 10:40:29 +00:00
|
|
|
flv.Unmarshal(it.Value())
|
|
|
|
fmt.Printf("[global] F:%d N:%q V:%s\n", folder, name, flv)
|
2015-10-23 19:02:38 +00:00
|
|
|
|
|
|
|
case db.KeyTypeBlock:
|
2016-07-04 10:40:29 +00:00
|
|
|
folder := binary.BigEndian.Uint32(key[1:])
|
|
|
|
hash := key[1+4 : 1+4+32]
|
|
|
|
name := nulString(key[1+4+32:])
|
|
|
|
fmt.Printf("[block] F:%d H:%x N:%q I:%d\n", folder, hash, name, binary.BigEndian.Uint32(it.Value()))
|
2015-10-23 19:02:38 +00:00
|
|
|
|
|
|
|
case db.KeyTypeDeviceStatistic:
|
2020-05-17 09:06:14 +00:00
|
|
|
fmt.Printf("[dstat] K:%x V:%x\n", key, it.Value())
|
2015-10-23 19:02:38 +00:00
|
|
|
|
|
|
|
case db.KeyTypeFolderStatistic:
|
2020-05-17 09:06:14 +00:00
|
|
|
fmt.Printf("[fstat] K:%x V:%x\n", key, it.Value())
|
2015-10-23 19:02:38 +00:00
|
|
|
|
|
|
|
case db.KeyTypeVirtualMtime:
|
2016-08-06 13:05:59 +00:00
|
|
|
folder := binary.BigEndian.Uint32(key[1:])
|
|
|
|
name := nulString(key[1+4:])
|
|
|
|
val := it.Value()
|
|
|
|
var real, virt time.Time
|
|
|
|
real.UnmarshalBinary(val[:len(val)/2])
|
|
|
|
virt.UnmarshalBinary(val[len(val)/2:])
|
|
|
|
fmt.Printf("[mtime] F:%d N:%q R:%v V:%v\n", folder, name, real, virt)
|
2016-07-04 10:40:29 +00:00
|
|
|
|
|
|
|
case db.KeyTypeFolderIdx:
|
2020-05-17 09:06:14 +00:00
|
|
|
key := binary.BigEndian.Uint32(key[1:])
|
2016-07-04 10:40:29 +00:00
|
|
|
fmt.Printf("[folderidx] K:%d V:%q\n", key, it.Value())
|
|
|
|
|
|
|
|
case db.KeyTypeDeviceIdx:
|
2020-05-17 09:06:14 +00:00
|
|
|
key := binary.BigEndian.Uint32(key[1:])
|
2016-07-04 10:40:29 +00:00
|
|
|
val := it.Value()
|
2020-06-07 08:31:12 +00:00
|
|
|
device := "<nil>"
|
|
|
|
if len(val) > 0 {
|
|
|
|
dev, err := protocol.DeviceIDFromBytes(val)
|
|
|
|
if err != nil {
|
|
|
|
device = fmt.Sprintf("<invalid %d bytes>", len(val))
|
|
|
|
} else {
|
|
|
|
device = dev.String()
|
|
|
|
}
|
2016-07-04 10:40:29 +00:00
|
|
|
}
|
2020-06-07 08:31:12 +00:00
|
|
|
fmt.Printf("[deviceidx] K:%d V:%s\n", key, device)
|
2015-10-23 19:02:38 +00:00
|
|
|
|
2020-01-31 07:27:20 +00:00
|
|
|
case db.KeyTypeIndexID:
|
2020-05-17 09:06:14 +00:00
|
|
|
device := binary.BigEndian.Uint32(key[1:])
|
|
|
|
folder := binary.BigEndian.Uint32(key[5:])
|
2020-01-31 07:27:20 +00:00
|
|
|
fmt.Printf("[indexid] D:%d F:%d I:%x\n", device, folder, it.Value())
|
|
|
|
|
|
|
|
case db.KeyTypeFolderMeta:
|
2020-05-17 09:06:14 +00:00
|
|
|
folder := binary.BigEndian.Uint32(key[1:])
|
2020-01-31 07:27:20 +00:00
|
|
|
fmt.Printf("[foldermeta] F:%d V:%x\n", folder, it.Value())
|
|
|
|
|
|
|
|
case db.KeyTypeMiscData:
|
2020-05-17 09:06:14 +00:00
|
|
|
fmt.Printf("[miscdata] K:%q V:%q\n", key[1:], it.Value())
|
2020-01-31 07:27:20 +00:00
|
|
|
|
|
|
|
case db.KeyTypeSequence:
|
2020-05-17 09:06:14 +00:00
|
|
|
folder := binary.BigEndian.Uint32(key[1:])
|
|
|
|
seq := binary.BigEndian.Uint64(key[5:])
|
2020-01-31 07:27:20 +00:00
|
|
|
fmt.Printf("[sequence] F:%d S:%d V:%q\n", folder, seq, it.Value())
|
|
|
|
|
|
|
|
case db.KeyTypeNeed:
|
2020-05-17 09:06:14 +00:00
|
|
|
folder := binary.BigEndian.Uint32(key[1:])
|
|
|
|
file := string(key[5:])
|
2020-01-31 07:27:20 +00:00
|
|
|
fmt.Printf("[need] F:%d V:%q\n", folder, file)
|
|
|
|
|
|
|
|
case db.KeyTypeBlockList:
|
2020-05-17 09:06:14 +00:00
|
|
|
fmt.Printf("[blocklist] H:%x\n", key[1:])
|
|
|
|
|
|
|
|
case db.KeyTypeBlockListMap:
|
|
|
|
folder := binary.BigEndian.Uint32(key[1:])
|
|
|
|
hash := key[5:37]
|
|
|
|
fileName := string(key[37:])
|
|
|
|
fmt.Printf("[blocklistmap] F:%d H:%x N:%s\n", folder, hash, fileName)
|
|
|
|
|
|
|
|
case db.KeyTypeVersion:
|
|
|
|
fmt.Printf("[version] H:%x\n", key[1:])
|
2020-01-31 07:27:20 +00:00
|
|
|
|
2015-10-23 19:02:38 +00:00
|
|
|
default:
|
2020-05-17 09:06:14 +00:00
|
|
|
fmt.Printf("[??? %d]\n %x\n %x\n", key[0], key, it.Value())
|
2015-10-23 19:02:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|