frontend: move started file at a dedicated path

This commit is contained in:
nemunaire 2018-01-22 18:09:05 +01:00
parent 3f1f60030c
commit 2e3b262a78
2 changed files with 7 additions and 6 deletions

View file

@ -17,12 +17,14 @@ func main() {
var bind = flag.String("bind", "127.0.0.1:8080", "Bind port/socket") 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 prefix = flag.String("prefix", "/", "Request path prefix to strip (from proxy)")
var teamsDir = flag.String("teams", "./TEAMS/", "Base directory where find existing teams") var teamsDir = flag.String("teams", "./TEAMS/", "Base directory where find existing teams")
flag.StringVar(&settings.SettingsDir, "settings", settings.SettingsDir, "Base directory where load and save settings") flag.StringVar(&settings.SettingsDir, "settings", settings.SettingsDir, "Base directory where read settings")
flag.StringVar(&startedFile, "startedFile", startedFile, "Path to the file to create/remove whether or not the challenge is running")
flag.StringVar(&SubmissionDir, "submission", "./submissions/", "Base directory where save submissions") flag.StringVar(&SubmissionDir, "submission", "./submissions/", "Base directory where save submissions")
flag.Parse() flag.Parse()
log.SetPrefix("[frontend] ") log.SetPrefix("[frontend] ")
startedFile = path.Clean(startedFile)
SubmissionDir = path.Clean(SubmissionDir) SubmissionDir = path.Clean(SubmissionDir)
TmpSubmissionDir = path.Join(SubmissionDir, ".tmp") TmpSubmissionDir = path.Join(SubmissionDir, ".tmp")

View file

@ -3,19 +3,18 @@ package main
import ( import (
"log" "log"
"os" "os"
"path"
"time" "time"
fronttime "srs.epita.fr/fic-server/frontend/time" fronttime "srs.epita.fr/fic-server/frontend/time"
"srs.epita.fr/fic-server/settings" "srs.epita.fr/fic-server/settings"
) )
const startedFile = "started" var startedFile = "started"
var touchTimer *time.Timer = nil var touchTimer *time.Timer = nil
func touchStartedFile() { func touchStartedFile() {
if fd, err := os.Create(path.Join(settings.SettingsDir, startedFile)); err == nil { if fd, err := os.Create(startedFile); err == nil {
log.Println("Started! Go, Go, Go!!") log.Println("Started! Go, Go, Go!!")
fd.Close() fd.Close()
} else { } else {
@ -32,8 +31,8 @@ func reloadSettings(config settings.FICSettings) {
if startSub > 0 { if startSub > 0 {
log.Println("Challenge will starts at", config.Start, "in", startSub) log.Println("Challenge will starts at", config.Start, "in", startSub)
if _, err := os.Stat(path.Join(settings.SettingsDir, startedFile)); !os.IsNotExist(err) { if _, err := os.Stat(startedFile); !os.IsNotExist(err) {
os.Remove(path.Join(settings.SettingsDir, startedFile)) os.Remove(startedFile)
} }
touchTimer = time.AfterFunc(config.Start.Sub(time.Now().Add(time.Duration(1 * time.Second))), touchStartedFile) touchTimer = time.AfterFunc(config.Start.Sub(time.Now().Add(time.Duration(1 * time.Second))), touchStartedFile)