(updatedDB ComDB)
| 9 | ) |
| 10 | |
| 11 | func WriteComDB(updatedDB ComDB) error { |
| 12 | functionName := "WriteComDB" |
| 13 | |
| 14 | // Stringify updated DB for write |
| 15 | updatedDBString, marshalErr := json.MarshalIndent(updatedDB, "", " ") |
| 16 | if marshalErr != nil { |
| 17 | return fmt.Errorf("%v: %w", functionName, marshalErr) |
| 18 | } |
| 19 | |
| 20 | // Write to Pluralith UI bus file (WriteFile replaces all file contents) |
| 21 | if writeErr := os.WriteFile(auxiliary.StateInstance.ComDBPath, updatedDBString, 0700); writeErr != nil { |
| 22 | return fmt.Errorf("%v: %w", functionName, writeErr) |
| 23 | } |
| 24 | |
| 25 | // Unlock comDB after write |
| 26 | if unlockErr := dblock.UpdateDBLock(false); unlockErr != nil { |
| 27 | return fmt.Errorf("failed to updated lock -> %v: %w", functionName, unlockErr) |
| 28 | } |
| 29 | |
| 30 | return nil |
| 31 | } |
| 32 | |
| 33 | // var writeRetries int = 0 |
| 34 | // var lock bool = true // Initializing local lock -> default: locked |
no outgoing calls
no test coverage detected