From 7d35337f339184ac8c0580b85b126888a20c5e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Grill?= Date: Tue, 17 Sep 2024 05:13:03 +0200 Subject: [PATCH] extract a method --- bindings/bindings.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/bindings/bindings.go b/bindings/bindings.go index f9012cd..1d17811 100644 --- a/bindings/bindings.go +++ b/bindings/bindings.go @@ -122,6 +122,18 @@ type InstanceContext struct { FileStateCallback func(core.FileSyncState) } +func (context InstanceContext) ConnectionStateChanged(id string, syninprogress bool, err error) { + if context.StateCallback == nil { + return + } + state := core.ConnectionState{ + ID: id, + SyncInProgress: syninprogress, + LastSyncError: err, + } + context.StateCallback(state) +} + func BindVirtualizationInstance(id string, localpath string, remotefs afero.Fs, context InstanceContext) (io.Closer, error) { var closer core.Virtualization var err error @@ -140,25 +152,13 @@ func BindVirtualizationInstance(id string, localpath string, remotefs afero.Fs, closer.SetFileStateHandler(context.FileStateCallback) internalSynchronize := func() { - context.StateCallback(core.ConnectionState{ - ID: id, - SyncInProgress: true, - LastSyncError: nil, - }) + context.ConnectionStateChanged(id, true, nil) err = closer.PerformSynchronization() if err != nil { context.Logger.Err(err).Send() - context.StateCallback(core.ConnectionState{ - ID: id, - SyncInProgress: false, - LastSyncError: err, - }) + context.ConnectionStateChanged(id, false, err) } else { - context.StateCallback(core.ConnectionState{ - ID: id, - SyncInProgress: false, - LastSyncError: nil, - }) + context.ConnectionStateChanged(id, false, nil) } }