diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2024-06-07 00:07:06 +0200 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2024-06-25 12:41:13 +0000 |
| commit | 5a06e4f2755e1265f34acc3fb9d819a7a22b7cd0 (patch) | |
| tree | abe5a6670f5bbe91b3c50ae1d796fd34f8e22ab4 /client/client.go | |
| parent | 0de98aeaa92080519ff0e194fc9246ddd79aca6d (diff) | |
Client: More frequent state file saving
Diffstat (limited to 'client/client.go')
| -rw-r--r-- | client/client.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/client/client.go b/client/client.go index 79de902..ac13e62 100644 --- a/client/client.go +++ b/client/client.go @@ -211,6 +211,7 @@ func (c *Client) AuthDone(id string, t srvtypes.Type) { log.Logger.Debugf("unhandled auth done main transition: %v", err) } c.MarkOrganizationsExpired(t) + c.TrySave() } // TokensUpdated is called when tokens are updated @@ -304,15 +305,21 @@ func (c *Client) locationCallback(ck *cookie.Cookie, orgID string) error { return err } srv.CountryCode = loc + c.TrySave() return nil } // TrySave tries to save the internal state file // If an error occurs it logs it func (c *Client) TrySave() { + log.Logger.Debugf("saving state file") + if c.cfg == nil { + log.Logger.Warningf("no state file to save") + return + } err := c.cfg.Save() if err != nil { - log.Logger.Warningf("failed to save configuration: %v", err) + log.Logger.Warningf("failed to save state file: %v", err) } } @@ -400,6 +407,7 @@ func (c *Client) GetConfig(ck *cookie.Cookie, identifier string, _type srvtypes. // go back to the previous state if an error occurred c.FSM.GoTransition(previousState) //nolint:errcheck } + c.TrySave() }() identifier, err = c.convertIdentifier(identifier, _type) @@ -462,6 +470,7 @@ func (c *Client) RemoveServer(identifier string, _type srvtypes.Type) (err error return i18nerr.WrapInternalf(err, "Failed to remove server: '%s'", identifier) } c.MarkOrganizationsExpired(_type) + c.TrySave() return nil } @@ -481,6 +490,7 @@ func (c *Client) SetProfileID(pID string) error { return i18nerr.WrapInternalf(err, "Failed to set the profile ID: '%s'", pID) } srv.Profiles.Current = pID + c.TrySave() return nil } @@ -507,6 +517,7 @@ func (c *Client) retrieveTokens(sid string, t srvtypes.Type) (*eduoauth.Token, e // Cleanup cleans up the VPN connection by sending a /disconnect func (c *Client) Cleanup(ck *cookie.Cookie) error { + defer c.TrySave() // cleanup proxyguard cerr := c.proxy.Cancel() if cerr != nil { @@ -543,6 +554,7 @@ func (c *Client) SetSecureLocation(orgID string, countryCode string) error { return i18nerr.WrapInternalf(err, "Failed to get the secure internet server with id: '%s' for setting a location", orgID) } srv.CountryCode = countryCode + defer c.TrySave() // no cached location profiles if srv.LocationProfiles == nil { |
