From d1cc1828b8b299d4cd77cfb39db1a23ae9a976c7 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 14 Apr 2015 20:59:06 +0900 Subject: [PATCH] Improve ItemStarted/ItemFinished events - Remove full details from ItemStarted (unnecessary, incorrect CamelCase) - Add "type" ("file" or "dir") to both events - Add "action" (what we tried to do - "delete" or "update") to both events. --- internal/db/truncated.go | 9 ------ internal/model/rwfolder.go | 59 ++++++++++++++++++++++++++------------ 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/internal/db/truncated.go b/internal/db/truncated.go index afb8e7f15..3fa7fcca5 100644 --- a/internal/db/truncated.go +++ b/internal/db/truncated.go @@ -13,15 +13,6 @@ type FileInfoTruncated struct { ActualSize int64 } -func ToTruncated(file protocol.FileInfo) FileInfoTruncated { - t := FileInfoTruncated{ - FileInfo: file, - ActualSize: file.Size(), - } - t.FileInfo.Blocks = nil - return t -} - func (f *FileInfoTruncated) UnmarshalXDR(bs []byte) error { err := f.FileInfo.UnmarshalXDR(bs) f.ActualSize = f.FileInfo.Size() diff --git a/internal/model/rwfolder.go b/internal/model/rwfolder.go index ceb8e0a92..f4ed74f1a 100644 --- a/internal/model/rwfolder.go +++ b/internal/model/rwfolder.go @@ -476,15 +476,19 @@ nextFile: func (p *rwFolder) handleDir(file protocol.FileInfo) { var err error events.Default.Log(events.ItemStarted, map[string]interface{}{ - "folder": p.folder, - "item": file.Name, - "details": db.ToTruncated(file), + "folder": p.folder, + "item": file.Name, + "type": "dir", + "action": "update", }) + defer func() { events.Default.Log(events.ItemFinished, map[string]interface{}{ "folder": p.folder, "item": file.Name, "error": err, + "type": "dir", + "action": "update", }) }() @@ -555,15 +559,18 @@ func (p *rwFolder) handleDir(file protocol.FileInfo) { func (p *rwFolder) deleteDir(file protocol.FileInfo) { var err error events.Default.Log(events.ItemStarted, map[string]interface{}{ - "folder": p.folder, - "item": file.Name, - "details": db.ToTruncated(file), + "folder": p.folder, + "item": file.Name, + "type": "dir", + "action": "delete", }) defer func() { events.Default.Log(events.ItemFinished, map[string]interface{}{ "folder": p.folder, "item": file.Name, "error": err, + "type": "dir", + "action": "delete", }) }() @@ -590,15 +597,18 @@ func (p *rwFolder) deleteDir(file protocol.FileInfo) { func (p *rwFolder) deleteFile(file protocol.FileInfo) { var err error events.Default.Log(events.ItemStarted, map[string]interface{}{ - "folder": p.folder, - "item": file.Name, - "details": db.ToTruncated(file), + "folder": p.folder, + "item": file.Name, + "type": "file", + "action": "delete", }) defer func() { events.Default.Log(events.ItemFinished, map[string]interface{}{ "folder": p.folder, "item": file.Name, "error": err, + "type": "file", + "action": "delete", }) }() @@ -629,25 +639,31 @@ func (p *rwFolder) deleteFile(file protocol.FileInfo) { func (p *rwFolder) renameFile(source, target protocol.FileInfo) { var err error events.Default.Log(events.ItemStarted, map[string]interface{}{ - "folder": p.folder, - "item": source.Name, - "details": db.ToTruncated(source), + "folder": p.folder, + "item": source.Name, + "type": "file", + "action": "delete", }) events.Default.Log(events.ItemStarted, map[string]interface{}{ - "folder": p.folder, - "item": target.Name, - "details": db.ToTruncated(source), + "folder": p.folder, + "item": target.Name, + "type": "file", + "action": "update", }) defer func() { events.Default.Log(events.ItemFinished, map[string]interface{}{ "folder": p.folder, "item": source.Name, "error": err, + "type": "file", + "action": "delete", }) events.Default.Log(events.ItemFinished, map[string]interface{}{ "folder": p.folder, "item": target.Name, "error": err, + "type": "file", + "action": "update", }) }() @@ -698,9 +714,10 @@ func (p *rwFolder) renameFile(source, target protocol.FileInfo) { // changed file. func (p *rwFolder) handleFile(file protocol.FileInfo, copyChan chan<- copyBlocksState, finisherChan chan<- *sharedPullerState) { events.Default.Log(events.ItemStarted, map[string]interface{}{ - "folder": p.folder, - "item": file.Name, - "details": db.ToTruncated(file), + "folder": p.folder, + "item": file.Name, + "type": "file", + "action": "update", }) curFile, ok := p.model.CurrentFolderFile(p.folder, file.Name) @@ -723,6 +740,8 @@ func (p *rwFolder) handleFile(file protocol.FileInfo, copyChan chan<- copyBlocks "folder": p.folder, "item": file.Name, "error": err, + "type": "file", + "action": "update", }) return } @@ -994,6 +1013,8 @@ func (p *rwFolder) performFinish(state *sharedPullerState) { "folder": p.folder, "item": state.file.Name, "error": err, + "type": "file", + "action": "update", }) }() @@ -1097,6 +1118,8 @@ func (p *rwFolder) finisherRoutine(in <-chan *sharedPullerState) { "folder": p.folder, "item": state.file.Name, "error": state.failed(), + "type": "file", + "action": "update", }) } p.model.receivedFile(p.folder, state.file.Name)