1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-11 02:13:41 +09:00

debugTree: save modify time, add unanonymized option

This commit is contained in:
Roman Khafizianov 2022-01-19 09:06:29 +01:00
parent 11e1b053c1
commit aeeb273991
No known key found for this signature in database
GPG key ID: F07A7D55A2684852
7 changed files with 692 additions and 628 deletions

View file

@ -24,7 +24,7 @@ var (
var dumpTree = &cobra.Command{
Use: "dump-tree",
Short: "Dumps anonymized tree of changes for specific thread",
Short: "Dumps tree of changes for specific thread",
Run: func(c *cobra.Command, args []string) {
if debugAccount == "" {
console.Fatal("please specify account")
@ -47,7 +47,7 @@ var dumpTree = &cobra.Command{
dbg := app.MustComponent(debug.CName).(debug.Debug)
filename, err := dbg.DumpTree(debugThread, debugOutputFile)
filename, err := dbg.DumpTree(debugThread, debugOutputFile, false)
if err != nil {
console.Fatal("failed to dump tree: %s", err.Error())
}

View file

@ -134,7 +134,7 @@ func (mw *Middleware) DebugTree(req *pb.RpcDebugTreeRequest) *pb.RpcDebugTreeRes
}
dbg := app.MustComponent(debug.CName).(debug.Debug)
filename, err := dbg.DumpTree(req.BlockId, req.Path)
filename, err := dbg.DumpTree(req.BlockId, req.Path, !req.Unanonymized)
return response(err, filename)
}

View file

@ -21,7 +21,7 @@ func New() Debug {
type Debug interface {
app.Component
DumpTree(blockId, path string) (filename string, err error)
DumpTree(blockId, path string, anonymize bool) (filename string, err error)
DumpLocalstore(objectIds []string, path string) (filename string, err error)
}
@ -40,12 +40,12 @@ func (d *debug) Name() (name string) {
return CName
}
func (d *debug) DumpTree(blockId, path string) (filename string, err error) {
func (d *debug) DumpTree(blockId, path string, anonymize bool) (filename string, err error) {
block, err := d.core.GetBlock(blockId)
if err != nil {
return
}
builder := &treeBuilder{b: block, s: d.store}
builder := &treeBuilder{b: block, s: d.store, anonymized: anonymize}
return builder.Build(path)
}

View file

@ -21,11 +21,12 @@ import (
)
type treeBuilder struct {
log *log.Logger
b core.SmartBlock
changes map[string]struct{}
zw *zip.Writer
s objectstore.ObjectStore
log *log.Logger
b core.SmartBlock
changes map[string]struct{}
zw *zip.Writer
s objectstore.ObjectStore
anonymized bool
}
func (b *treeBuilder) Build(path string) (filename string, err error) {
@ -122,6 +123,16 @@ func (b *treeBuilder) writeChanges(logs []core.SmartblockLog) (err error) {
return
}
func createFileWithDateInZip(zw *zip.Writer, name string, modified time.Time) (io.Writer, error) {
header := &zip.FileHeader{
Name: name,
Method: zip.Deflate,
Modified: modified,
}
return zw.CreateHeader(header)
}
func (b *treeBuilder) writeChange(id string) (nextIds []string) {
if _, ok := b.changes[id]; ok {
return
@ -141,9 +152,18 @@ func (b *treeBuilder) writeChange(id string) (nextIds []string) {
Id: id,
Account: rec.AccountID,
Device: rec.LogID,
Change: anonymize.Change(chp),
}
chw, err := b.zw.Create(id + ".json")
if b.anonymized {
ch.Change = anonymize.Change(chp)
} else {
ch.Change = chp
}
chw, err := b.zw.CreateHeader(&zip.FileHeader{
Name: id + ".json",
Method: zip.Deflate,
Modified: time.Unix(ch.Timestamp, 0),
})
if err != nil {
b.log.Printf("create file in zip error: %v", err)
return

View file

@ -6947,6 +6947,7 @@ commands acceptable only for text blocks, others will be ignored
| ----- | ---- | ----- | ----------- |
| blockId | [string](#string) | | |
| path | [string](#string) | | |
| unanonymized | [bool](#bool) | | set to true to disable mocking of the actual data inside changes |

File diff suppressed because it is too large Load diff

View file

@ -4074,6 +4074,7 @@ message Rpc {
message Request {
string blockId = 1;
string path = 2;
bool unanonymized = 3; // set to true to disable mocking of the actual data inside changes
}
message Response {