frontend: copy settings.json on settings reload (to handle delayed settings propagation)
This commit is contained in:
parent
4820d42327
commit
caea02bb4d
6 changed files with 29 additions and 4 deletions
|
@ -1,8 +1,10 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
"srs.epita.fr/fic-server/settings"
|
||||
|
@ -10,6 +12,8 @@ import (
|
|||
|
||||
var startedFile = "started"
|
||||
|
||||
var SettingsDistDir = "./SETTINGSDIST/"
|
||||
|
||||
var touchTimer *time.Timer = nil
|
||||
var challengeStart time.Time
|
||||
var challengeEnd time.Time
|
||||
|
@ -24,6 +28,15 @@ func touchStartedFile() {
|
|||
}
|
||||
|
||||
func reloadSettings(config settings.FICSettings) {
|
||||
// Copy the new settings file for distribution
|
||||
if data, err := ioutil.ReadFile(path.Join(settings.SettingsDir, settings.SettingsFile)); err != nil {
|
||||
log.Println("Unable to read settings file:", err)
|
||||
} else if err = ioutil.WriteFile(path.Join(SettingsDistDir, settings.SettingsFile + ".tmp"), data, 0644); err != nil {
|
||||
log.Println("Unable to write tmp settings file:", err)
|
||||
} else if err := os.Rename(path.Join(SettingsDistDir, settings.SettingsFile + ".tmp"), path.Join(SettingsDistDir, settings.SettingsFile)); err != nil {
|
||||
log.Println("Unable to move new settings file:", err)
|
||||
}
|
||||
|
||||
if challengeStart != config.Start || challengeEnd != config.End {
|
||||
if touchTimer != nil {
|
||||
touchTimer.Stop()
|
||||
|
|
Reference in a new issue