syncthing/cmd/stindex/main.go

87 lines
2.1 KiB
Go
Raw Normal View History

2014-11-16 21:13:20 +01:00
// Copyright (C) 2014 The Syncthing Authors.
2014-09-29 21:43:32 +02:00
//
2015-03-07 21:36:35 +01:00
// 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,
// You can obtain one at http://mozilla.org/MPL/2.0/.
2014-07-06 14:46:48 +02:00
package main
import (
2015-05-04 14:01:54 +02:00
"encoding/binary"
2014-07-06 14:46:48 +02:00
"flag"
"fmt"
"log"
"os"
2015-08-06 11:29:25 +02:00
"github.com/syncthing/syncthing/lib/db"
2015-09-22 19:38:46 +02:00
"github.com/syncthing/syncthing/lib/protocol"
2014-07-06 14:46:48 +02:00
"github.com/syndtr/goleveldb/leveldb"
2015-05-04 14:01:54 +02:00
"github.com/syndtr/goleveldb/leveldb/opt"
2014-07-06 14:46:48 +02:00
)
func main() {
log.SetFlags(0)
log.SetOutput(os.Stdout)
flag.Parse()
2015-05-04 14:01:54 +02:00
ldb, err := leveldb.OpenFile(flag.Arg(0), &opt.Options{
ErrorIfMissing: true,
Strict: opt.StrictAll,
OpenFilesCacheCapacity: 100,
})
2014-07-06 14:46:48 +02:00
if err != nil {
log.Fatal(err)
}
2015-05-04 14:01:54 +02:00
it := ldb.NewIterator(nil, nil)
var dev protocol.DeviceID
for it.Next() {
key := it.Key()
switch key[0] {
case db.KeyTypeDevice:
folder := nulString(key[1 : 1+64])
devBytes := key[1+64 : 1+64+32]
name := nulString(key[1+64+32:])
copy(dev[:], devBytes)
fmt.Printf("[device] F:%q N:%q D:%v\n", folder, name, dev)
var f protocol.FileInfo
err := f.UnmarshalXDR(it.Value())
if err != nil {
log.Fatal(err)
}
fmt.Printf(" N:%q\n F:%#o\n M:%d\n V:%v\n S:%d\n B:%d\n", f.Name, f.Flags, f.Modified, f.Version, f.Size(), len(f.Blocks))
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())
case db.KeyTypeBlock:
folder := nulString(key[1 : 1+64])
hash := key[1+64 : 1+64+32]
name := nulString(key[1+64+32:])
fmt.Printf("[block] F:%q H:%x N:%q I:%d\n", folder, hash, name, binary.BigEndian.Uint32(it.Value()))
case db.KeyTypeDeviceStatistic:
2015-05-12 11:47:30 +02:00
fmt.Printf("[dstat]\n %x\n %x\n", it.Key(), it.Value())
2015-05-04 14:01:54 +02:00
case db.KeyTypeFolderStatistic:
2015-05-12 11:47:30 +02:00
fmt.Printf("[fstat]\n %x\n %x\n", it.Key(), it.Value())
2015-05-04 14:01:54 +02:00
default:
2015-05-12 11:47:30 +02:00
fmt.Printf("[???]\n %x\n %x\n", it.Key(), it.Value())
2015-05-04 14:01:54 +02:00
}
}
}
func nulString(bs []byte) string {
for i := range bs {
if bs[i] == 0 {
return string(bs[:i])
2014-07-06 14:46:48 +02:00
}
}
2015-05-04 14:01:54 +02:00
return string(bs)
2014-07-06 14:46:48 +02:00
}