Move settings and started file into SETTINGS directory

This commit is contained in:
nemunaire 2017-11-22 02:00:40 +01:00 committed by Pierre-Olivier Mercier
commit f1d6b92267
7 changed files with 22 additions and 10 deletions

View file

@ -16,6 +16,7 @@ func main() {
var bind = flag.String("bind", "127.0.0.1:8080", "Bind port/socket")
var prefix = flag.String("prefix", "", "Request path prefix to strip (from proxy)")
var teamsDir = flag.String("teams", "./TEAMS/", "Base directory where find existing teams")
flag.StringVar(&SettingsDir, "settings", "./SETTINGS/", "Base directory where load and save settings")
flag.StringVar(&SubmissionDir, "submission", "./submissions/", "Base directory where save submissions")
flag.Parse()
@ -32,7 +33,7 @@ func main() {
}
// Load configuration
settings.LoadAndWatchSettings(path.Join(*teamsDir, settings.SettingsFile), reloadSettings)
settings.LoadAndWatchSettings(path.Join(SettingsDir, settings.SettingsFile), reloadSettings)
// Register handlers
http.Handle(fmt.Sprintf("%s/chname/", *prefix), http.StripPrefix(fmt.Sprintf("%s/chname/", *prefix), submissionTeamChecker{"name change", ChNameHandler, *teamsDir}))

View file

@ -12,10 +12,12 @@ import (
const startedFile = "started"
var SettingsDir string
var touchTimer *time.Timer = nil
func touchStartedFile() {
if fd, err := os.Create(path.Join(SubmissionDir, startedFile)); err == nil {
if fd, err := os.Create(path.Join(SettingsDir, startedFile)); err == nil {
log.Println("Started! Go, Go, Go!!")
fd.Close()
} else {
@ -32,8 +34,8 @@ func reloadSettings(config settings.FICSettings) {
if startSub > 0 {
log.Println("Challenge will starts at", config.Start, "in", startSub)
if _, err := os.Stat(path.Join(SubmissionDir, startedFile)); !os.IsNotExist(err) {
os.Remove(path.Join(SubmissionDir, startedFile))
if _, err := os.Stat(path.Join(SettingsDir, startedFile)); !os.IsNotExist(err) {
os.Remove(path.Join(SettingsDir, startedFile))
}
touchTimer = time.AfterFunc(config.Start.Sub(time.Now().Add(time.Duration(1 * time.Second))), touchStartedFile)