File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ func (s *AppState) Read(configDir string) error {
6161 return nil
6262}
6363
64+
6465func (s * AppState ) Write () error {
6566 s .Lock ()
6667 defer s .Unlock ()
@@ -76,7 +77,19 @@ func (s *AppState) Write() error {
7677 if err := json .NewEncoder (tmpFile ).Encode (s ); err != nil {
7778 return fmt .Errorf ("failed writing marshalled app state: %w" , err )
7879 }
79- }
80+ }
81+ if err := s .persistStateWithoutCredentials (tmpFile ); err != nil {
82+ return err
83+ }
84+
85+ if err := os .Rename (tmpFile .Name (), s .path ); err != nil {
86+ return fmt .Errorf ("failed replacing app state file: %w" , err )
87+ }
88+
89+ return nil
90+ }
91+
92+ func (s * AppState ) persistStateWithoutCredentials (tmpFile * os.File ) error {
8093 persistedState := struct {
8194 DeviceId string `json:"device_id"`
8295 EventManager json.RawMessage `json:"event_manager"`
@@ -90,12 +103,6 @@ func (s *AppState) Write() error {
90103 if err := json .NewEncoder (tmpFile ).Encode (& persistedState ); err != nil {
91104 return fmt .Errorf ("failed writing marshalled app state: %w" , err )
92105 }
93-
94-
95- if err := os .Rename (tmpFile .Name (), s .path ); err != nil {
96- return fmt .Errorf ("failed replacing app state file: %w" , err )
97- }
98-
99106 return nil
100107}
101108
You can’t perform that action at this time.
0 commit comments