2015-10-23 12:02:38 -07: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-08 23:52:18 -07:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2015-10-23 12:02:38 -07:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
2016-08-06 06:05:59 -07:00
|
|
|
"time"
|
2015-10-23 12:02:38 -07:00
|
|
|
|
|
|
|
"github.com/syncthing/syncthing/lib/db"
|
2015-10-23 12:21:21 -07:00
|
|
|
"github.com/syncthing/syncthing/lib/protocol"
|
2015-10-23 12:02:38 -07:00
|
|
|
)
|
|
|
|
|
2018-10-10 02:34:24 -07:00
|
|
|
func dump(ldb *db.Lowlevel) {
|
2015-10-23 12:02:38 -07:00
|
|
|
it := ldb.NewIterator(nil, nil)
|
|
|
|
for it.Next() {
|
|
|
|
key := it.Key()
|
|
|
|
switch key[0] {
|
|
|
|
case db.KeyTypeDevice:
|
2016-07-04 03:40:29 -07: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 12:02:38 -07:00
|
|
|
|
|
|
|
var f protocol.FileInfo
|
2016-07-04 03:40:29 -07:00
|
|
|
err := f.Unmarshal(it.Value())
|
2015-10-23 12:02:38 -07:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2016-07-04 03:40:29 -07:00
|
|
|
fmt.Printf(" V:%v\n", f)
|
2015-10-23 12:02:38 -07:00
|
|
|
|
|
|
|
case db.KeyTypeGlobal:
|
2016-07-04 03:40:29 -07:00
|
|
|
folder := binary.BigEndian.Uint32(key[1:])
|
|
|
|
name := nulString(key[1+4:])
|
2016-05-31 12:29:26 -07:00
|
|
|
var flv db.VersionList
|
2016-07-04 03:40:29 -07:00
|
|
|
flv.Unmarshal(it.Value())
|
|
|
|
fmt.Printf("[global] F:%d N:%q V:%s\n", folder, name, flv)
|
2015-10-23 12:02:38 -07:00
|
|
|
|
|
|
|
case db.KeyTypeBlock:
|
2016-07-04 03:40:29 -07: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 12:02:38 -07:00
|
|
|
|
|
|
|
case db.KeyTypeDeviceStatistic:
|
2016-07-04 03:40:29 -07:00
|
|
|
fmt.Printf("[dstat] K:%x V:%x\n", it.Key(), it.Value())
|
2015-10-23 12:02:38 -07:00
|
|
|
|
|
|
|
case db.KeyTypeFolderStatistic:
|
2016-07-04 03:40:29 -07:00
|
|
|
fmt.Printf("[fstat] K:%x V:%x\n", it.Key(), it.Value())
|
2015-10-23 12:02:38 -07:00
|
|
|
|
|
|
|
case db.KeyTypeVirtualMtime:
|
2016-08-06 06:05:59 -07: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 03:40:29 -07:00
|
|
|
|
|
|
|
case db.KeyTypeFolderIdx:
|
|
|
|
key := binary.BigEndian.Uint32(it.Key()[1:])
|
|
|
|
fmt.Printf("[folderidx] K:%d V:%q\n", key, it.Value())
|
|
|
|
|
|
|
|
case db.KeyTypeDeviceIdx:
|
|
|
|
key := binary.BigEndian.Uint32(it.Key()[1:])
|
|
|
|
val := it.Value()
|
|
|
|
if len(val) == 0 {
|
|
|
|
fmt.Printf("[deviceidx] K:%d V:<nil>\n", key)
|
|
|
|
} else {
|
|
|
|
dev := protocol.DeviceIDFromBytes(val)
|
|
|
|
fmt.Printf("[deviceidx] K:%d V:%s\n", key, dev)
|
|
|
|
}
|
2015-10-23 12:02:38 -07:00
|
|
|
|
|
|
|
default:
|
|
|
|
fmt.Printf("[???]\n %x\n %x\n", it.Key(), it.Value())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|