cmd/syncthing: Rename event LocalDiskUpdated -> LocalChangeDetected

I think this better reflects what it means. Also tweaks the verbose
format to be more like our other things and lightly refactors the code
to not have the boolean and include the folder in the event.

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3121
This commit is contained in:
Jakob Borg
2016-05-19 07:01:43 +00:00
committed by Audrius Butkevicius
parent 86ca58e2a9
commit 1dbc310c9b
4 changed files with 23 additions and 20 deletions

View File

@@ -534,7 +534,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
// Event subscription for the API; must start early to catch the early events. The LocalDiskUpdated // Event subscription for the API; must start early to catch the early events. The LocalDiskUpdated
// event might overwhelm the event reciever in some situations so we will not subscribe to it here. // event might overwhelm the event reciever in some situations so we will not subscribe to it here.
apiSub := events.NewBufferedSubscription(events.Default.Subscribe(events.AllEvents&^events.LocalDiskUpdated), 1000) apiSub := events.NewBufferedSubscription(events.Default.Subscribe(events.AllEvents&^events.LocalChangeDetected), 1000)
if len(os.Getenv("GOMAXPROCS")) == 0 { if len(os.Getenv("GOMAXPROCS")) == 0 {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

View File

@@ -92,9 +92,10 @@ func (s *verboseService) formatEvent(ev events.Event) string {
data := ev.Data.(map[string]interface{}) data := ev.Data.(map[string]interface{})
return fmt.Sprintf("Folder %q is now %v", data["folder"], data["to"]) return fmt.Sprintf("Folder %q is now %v", data["folder"], data["to"])
case events.LocalDiskUpdated: case events.LocalChangeDetected:
data := ev.Data.(map[string]string) data := ev.Data.(map[string]string)
return fmt.Sprintf("%s a %s: [ %s ]", data["action"], data["type"], data["path"]) // Local change detected in folder "foo": modified file /Users/jb/whatever
return fmt.Sprintf("Local change detected in folder %q: %s %s %s", data["folder"], data["action"], data["type"], data["path"])
case events.RemoteIndexUpdated: case events.RemoteIndexUpdated:
data := ev.Data.(map[string]interface{}) data := ev.Data.(map[string]interface{})

View File

@@ -27,7 +27,7 @@ const (
DeviceRejected DeviceRejected
DevicePaused DevicePaused
DeviceResumed DeviceResumed
LocalDiskUpdated LocalChangeDetected
LocalIndexUpdated LocalIndexUpdated
RemoteIndexUpdated RemoteIndexUpdated
ItemStarted ItemStarted
@@ -62,8 +62,8 @@ func (t EventType) String() string {
return "DeviceDisconnected" return "DeviceDisconnected"
case DeviceRejected: case DeviceRejected:
return "DeviceRejected" return "DeviceRejected"
case LocalDiskUpdated: case LocalChangeDetected:
return "LocalDiskUpdated" return "LocalChangeDetected"
case LocalIndexUpdated: case LocalIndexUpdated:
return "LocalIndexUpdated" return "LocalIndexUpdated"
case RemoteIndexUpdated: case RemoteIndexUpdated:

View File

@@ -1235,14 +1235,21 @@ func sendIndexTo(initial bool, minLocalVer int64, conn protocol.Connection, fold
} }
func (m *Model) updateLocalsFromScanning(folder string, fs []protocol.FileInfo) { func (m *Model) updateLocalsFromScanning(folder string, fs []protocol.FileInfo) {
m.updateLocals(folder, fs, false) m.updateLocals(folder, fs)
// Fire the LocalChangeDetected event to notify listeners about local
// updates.
m.fmut.RLock()
path := m.folderCfgs[folder].Path()
m.fmut.RUnlock()
m.localChangeDetected(folder, path, fs)
} }
func (m *Model) updateLocalsFromPulling(folder string, fs []protocol.FileInfo) { func (m *Model) updateLocalsFromPulling(folder string, fs []protocol.FileInfo) {
m.updateLocals(folder, fs, true) m.updateLocals(folder, fs)
} }
func (m *Model) updateLocals(folder string, fs []protocol.FileInfo, fromPulling bool) { func (m *Model) updateLocals(folder string, fs []protocol.FileInfo) {
m.fmut.RLock() m.fmut.RLock()
files := m.folderFiles[folder] files := m.folderFiles[folder]
m.fmut.RUnlock() m.fmut.RUnlock()
@@ -1263,35 +1270,29 @@ func (m *Model) updateLocals(folder string, fs []protocol.FileInfo, fromPulling
"filenames": filenames, "filenames": filenames,
"version": files.LocalVersion(protocol.LocalDeviceID), "version": files.LocalVersion(protocol.LocalDeviceID),
}) })
// Lets us know if file/folder change was originated locally or from a network
// sync update. Now write these to a global log file.
if !fromPulling {
m.localDiskUpdated(m.folderCfgs[folder].Path(), fs)
}
} }
func (m *Model) localDiskUpdated(path string, files []protocol.FileInfo) { func (m *Model) localChangeDetected(folder, path string, files []protocol.FileInfo) {
// For windows paths, strip unwanted chars from the front // For windows paths, strip unwanted chars from the front
path = strings.Replace(path, `\\?\`, "", 1) path = strings.Replace(path, `\\?\`, "", 1)
for _, file := range files { for _, file := range files {
objType := "file" objType := "file"
action := "Modified" action := "modified"
// If our local vector is verison 1 AND it is the only version vector so far seen for this file then // If our local vector is verison 1 AND it is the only version vector so far seen for this file then
// it is a new file. Else if it is > 1 it's not new, and if it is 1 but another shortId version vector // it is a new file. Else if it is > 1 it's not new, and if it is 1 but another shortId version vector
// exists then it is new for us but created elsewhere so the file is still not new but modified by us. // exists then it is new for us but created elsewhere so the file is still not new but modified by us.
// Only if it is truly new do we change this to 'added', else we leave it as 'modified'. // Only if it is truly new do we change this to 'added', else we leave it as 'modified'.
if len(file.Version) == 1 && file.Version[0].Value == 1 { if len(file.Version) == 1 && file.Version[0].Value == 1 {
action = "Added" action = "added"
} }
if file.IsDirectory() { if file.IsDirectory() {
objType = "dir" objType = "dir"
} }
if file.IsDeleted() { if file.IsDeleted() {
action = "Deleted" action = "deleted"
} }
// If the file is a level or more deep then the forward slash seperator is embedded // If the file is a level or more deep then the forward slash seperator is embedded
@@ -1300,7 +1301,8 @@ func (m *Model) localDiskUpdated(path string, files []protocol.FileInfo) {
// And append it to the filepath // And append it to the filepath
path := filepath.Join(path, filename) path := filepath.Join(path, filename)
events.Default.Log(events.LocalDiskUpdated, map[string]string{ events.Default.Log(events.LocalChangeDetected, map[string]string{
"folder": folder,
"action": action, "action": action,
"type": objType, "type": objType,
"path": path, "path": path,